mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-19 09:51:16 -03:00
expand_cmdsubst: Make more errors known
These printed "Unknown error while evaluating command substitution".
Now they print something like
```
fish: for: status: cannot overwrite read-only variable
for status in foo; end
^~~~~^
in command substitution
fish: Invalid arguments
echo (for status in foo; end)
^~~~~~~~~~~~~~~~~~~~~~~^
```
for `echo (for status in foo; end)`
This is, of course, still not *great*. Mostly the `fish: Invalid
arguments` is basically entirely redundant.
An alternative is to simply skip the error message, but that requires some
more scaffolding (describe_with_prefix adds some error messages on its
own, so we can't simply say "don't add the prefix if we don't have a
message")
(cherry picked from commit 1b5eec2af6)
This commit is contained in:
@@ -666,6 +666,23 @@ static expand_result_t expand_cmdsubst(wcstring input, const operation_context_t
|
||||
case STATUS_NOT_EXECUTABLE:
|
||||
err = L"Command not executable";
|
||||
break;
|
||||
case STATUS_INVALID_ARGS:
|
||||
// TODO: Also overused
|
||||
// This is sent for:
|
||||
// invalid redirections or pipes (like `<&foo`),
|
||||
// invalid variables (invalid name or read-only) for for-loops,
|
||||
// switch $foo if $foo expands to more than one argument
|
||||
// time in a background job.
|
||||
err = L"Invalid arguments";
|
||||
break;
|
||||
case STATUS_EXPAND_ERROR:
|
||||
// Sent in `for $foo in ...` if $foo expands to more than one word
|
||||
err = L"Expansion error";
|
||||
break;
|
||||
case STATUS_UNMATCHED_WILDCARD:
|
||||
// Sent in `for $foo in ...` if $foo expands to more than one word
|
||||
err = L"Unmatched wildcard";
|
||||
break;
|
||||
default:
|
||||
err = L"Unknown error while evaluating command substitution";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user