Rationalize $status and errors

Prior to this fix, fish was rather inconsistent in when $status gets set
in response to an error. For example, a failed expansion like "$foo["
would not modify $status.

This makes the following inter-related changes:

1. String expansion now directly returns the value to set for $status on
error. The value is always used.

2. parser_t::eval() now directly returns the proc_status_t, which cleans
up a lot of call sites.

3. We expose a new function exec_subshell_for_expand() which ignores
$status but returns errors specifically related to subshell expansion.

4. We reify the notion of "expansion breaking" errors. These include
command-not-found, expand syntax errors, and others.

The upshot is we are more consistent about always setting $status on
errors.
This commit is contained in:
ridiculousfish
2020-01-23 17:34:46 -08:00
parent 81e78c78aa
commit 38f4330683
17 changed files with 364 additions and 308 deletions

View File

@@ -1033,16 +1033,13 @@ static void test_1_cancellation(const wchar_t *src) {
usleep(delay * 1E6);
pthread_kill(thread, SIGINT);
});
end_execution_reason_t ret = parser_t::principal_parser().eval(src, io_chain_t{filler});
eval_res_t res = parser_t::principal_parser().eval(src, io_chain_t{filler});
auto buffer = io_bufferfill_t::finish(std::move(filler));
if (buffer->buffer().size() != 0) {
err(L"Expected 0 bytes in out_buff, but instead found %lu bytes, for command %ls\n",
buffer->buffer().size(), src);
}
// TODO: cancelling out of command substitutions is currently reported as an error, not a
// cancellation.
// do_test(ret == end_execution_reason_t::cancelled);
(void)ret;
do_test(res.status.signal_exited() && res.status.signal_code() == SIGINT);
iothread_drain_all();
}