Combine status and pipestatus into statuses_t

In most places where we set one, we want to set both. Make this less
error-prone by combining them into a single type statuses_t.
This commit is contained in:
ridiculousfish
2019-02-25 01:21:32 -08:00
parent 47ff060b89
commit 1a4bb50cd5
8 changed files with 76 additions and 80 deletions

View File

@@ -261,7 +261,7 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(
auto else_cont = else_clause.try_get_child<g::else_continuation, 1>();
if (!else_cont) {
// 'if' condition failed, no else clause, return 0, we're done.
proc_set_last_status(STATUS_CMD_OK);
proc_set_last_statuses(statuses_t::just(STATUS_CMD_OK));
break;
} else {
// We have an 'else continuation' (either else-if or else).
@@ -289,7 +289,7 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(
parser->pop_block(ib);
} else {
// No job list means no sucessful conditions, so return 0 (issue #1443).
proc_set_last_status(STATUS_CMD_OK);
proc_set_last_statuses(statuses_t::just(STATUS_CMD_OK));
}
// It's possible there's a last-minute cancellation (issue #1297).
@@ -325,7 +325,7 @@ parse_execution_result_t parse_execution_context_t::run_function_statement(
}
io_streams_t streams(0); // no limit on the amount of output from builtin_function()
int err = builtin_function(*parser, streams, arguments, pstree, body);
proc_set_last_status(err);
proc_set_last_statuses(statuses_t::just(err));
if (!streams.err.empty()) {
this->report_error(header, L"%ls", streams.err.contents().c_str());
@@ -543,7 +543,8 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(
for (;;) {
// Save off the exit status if it came from the loop body. We'll restore it if the condition
// is false.
int cond_saved_status = first_cond_check ? EXIT_SUCCESS : proc_get_last_status();
auto cond_saved_status =
first_cond_check ? statuses_t::just(EXIT_SUCCESS) : proc_get_last_statuses();
first_cond_check = false;
// Check the condition.
@@ -559,7 +560,7 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(
if (cond_ret != parse_execution_success) {
break;
} else if (proc_get_last_status() != EXIT_SUCCESS) {
proc_set_last_status(cond_saved_status);
proc_set_last_statuses(cond_saved_status);
break;
}
@@ -636,7 +637,7 @@ parse_execution_result_t parse_execution_context_t::report_errors(
/// Reports an unmatched wildcard error and returns parse_execution_errored.
parse_execution_result_t parse_execution_context_t::report_unmatched_wildcard_error(
const parse_node_t &unmatched_wildcard) const {
proc_set_last_status(STATUS_UNMATCHED_WILDCARD);
proc_set_last_statuses(statuses_t::just(STATUS_UNMATCHED_WILDCARD));
report_error(unmatched_wildcard, WILDCARD_ERR_MSG, get_source(unmatched_wildcard).c_str());
return parse_execution_errored;
}
@@ -718,8 +719,7 @@ parse_execution_result_t parse_execution_context_t::handle_command_not_found(
// Set the last proc status appropriately.
int status = err_code == ENOENT ? STATUS_CMD_UNKNOWN : STATUS_NOT_EXECUTABLE;
proc_set_last_status(status);
proc_set_last_job_statuses({status});
proc_set_last_statuses(statuses_t::just(status));
return parse_execution_errored;
}
@@ -741,7 +741,7 @@ parse_execution_result_t parse_execution_context_t::expand_command(
expand_error_t expand_err =
expand_to_command_and_args(unexp_cmd, parser->vars(), out_cmd, out_args, &errors);
if (expand_err == EXPAND_ERROR) {
proc_set_last_status(STATUS_ILLEGAL_CMD);
proc_set_last_statuses(statuses_t::just(STATUS_ILLEGAL_CMD));
return report_errors(errors);
} else if (expand_err == EXPAND_WILDCARD_NO_MATCH) {
return report_unmatched_wildcard_error(statement);