From b2a1da602f79878f4b0adc4881216c928a542608 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 13 Apr 2019 16:57:00 -0500 Subject: [PATCH] Fix error propagation in parser_t::eval It was unconditionally returning `parse_execution_success`. This was causing certain parser errors to incorrectly return after evaluation with `$status` equal to `0`, as reported after `eval`, `source`, or sub-`fish` execution. --- src/parse_execution.cpp | 2 +- src/parser.cpp | 8 ++++---- src/parser.h | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index e2eccca1e..2afbc2155 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -1291,7 +1291,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo } job_reap(false); // clean up jobs - return parse_execution_success; + return populated_job ? parse_execution_success : parse_execution_errored; } parse_execution_result_t parse_execution_context_t::run_job_conjunction( diff --git a/src/parser.cpp b/src/parser.cpp index a36faa4f4..1a7e9ef3e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -631,17 +631,17 @@ int parser_t::eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_t std::fwprintf(stderr, L"%ls\n", backtrace_and_desc.c_str()); return 1; } - this->eval(ps, io, block_type); - return 0; + return this->eval(ps, io, block_type); } -void parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type) { +int parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type) { assert(block_type == TOP || block_type == SUBST); if (!ps->tree.empty()) { // Execute the first node. tnode_t start{&ps->tree, &ps->tree.front()}; - this->eval_node(ps, start, io, block_type, nullptr /* parent */); + return this->eval_node(ps, start, io, block_type, nullptr /* parent */); } + return 0; } template diff --git a/src/parser.h b/src/parser.h index 6648b069b..7cb075b3c 100644 --- a/src/parser.h +++ b/src/parser.h @@ -225,7 +225,8 @@ class parser_t : public std::enable_shared_from_this { int eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_type); /// Evaluate the parsed source ps. - void eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type); + /// \return 0 on success, 1 on a parse error. + int eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type); /// Evaluates a node. /// The node type must be grammar::statement or grammar::job_list.