From a4fd3c194e85b734bea8a619679c447f7dab82b6 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 11 Aug 2022 17:31:01 +0200 Subject: [PATCH] Pass location of the *command* node without decorators Fixes error location for unknown commands --- src/parse_execution.cpp | 6 +++--- tests/checks/command-not-found.fish | 12 ++++++------ tests/checks/vars_as_commands.fish | 5 +++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 79689668a..5dfd0c752 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -736,7 +736,7 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found( // ELOOP // ENAMETOOLONG return this->report_error( - STATUS_NOT_EXECUTABLE, statement, + STATUS_NOT_EXECUTABLE, statement.command, _(L"Unknown command. '%ls' exists but is not an executable file."), cmd); } @@ -791,7 +791,7 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found( // Here we want to report an error (so it shows a backtrace). // If the handler printed text, that's already shown, so error will be empty. - return this->report_error(STATUS_CMD_UNKNOWN, statement, error.c_str()); + return this->report_error(STATUS_CMD_UNKNOWN, statement.command, error.c_str()); } end_execution_reason_t parse_execution_context_t::expand_command( @@ -825,7 +825,7 @@ end_execution_reason_t parse_execution_context_t::expand_command( // Complain if the resulting expansion was empty, or expanded to an empty string. // For no-exec it's okay, as we can't really perform the expansion. if (out_cmd->empty() && !no_exec()) { - return this->report_error(STATUS_ILLEGAL_CMD, statement, + return this->report_error(STATUS_ILLEGAL_CMD, statement.command, _(L"The expanded command was empty.")); } return end_execution_reason_t::ok; diff --git a/tests/checks/command-not-found.fish b/tests/checks/command-not-found.fish index 2dbec5648..0253bfc0e 100644 --- a/tests/checks/command-not-found.fish +++ b/tests/checks/command-not-found.fish @@ -4,22 +4,22 @@ $fish -c "nonexistent-command-1234 banana rama" #CHECKERR: fish: Unknown command: nonexistent-command-1234 #CHECKERR: fish: #CHECKERR: nonexistent-command-1234 banana rama -#CHECKERR: ^ +#CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~^ $fish -C 'function fish_command_not_found; echo cmd-not-found; end' -ic "nonexistent-command-1234 1 2 3 4" #CHECKERR: cmd-not-found #CHECKERR: fish: #CHECKERR: nonexistent-command-1234 1 2 3 4 -#CHECKERR: ^ +#CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~^ $fish -C 'function fish_command_not_found; echo command-not-found $argv; end' -c "nonexistent-command-abcd foo bar baz" #CHECKERR: command-not-found nonexistent-command-abcd foo bar baz #CHECKERR: fish: #CHECKERR: nonexistent-command-abcd foo bar baz -#CHECKERR: ^ +#CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~^ $fish -C 'functions --erase fish_command_not_found' -c 'nonexistent-command apple friday' #CHECKERR: fish: Unknown command: nonexistent-command #CHECKERR: nonexistent-command apple friday -#CHECKERR: ^ +#CHECKERR: ^~~~~~~~~~~~~~~~~~^ command -v nonexistent-command-1234 echo $status @@ -30,14 +30,14 @@ echo $status # CHECKERR: {{.*}}: Unknown command: '{ echo; echo }' # CHECKERR: {{.*}}: '{ ... }' is not supported for grouping commands. Please use 'begin; ...; end' # CHECKERR: { echo; echo } -# CHECKERR: ^ +# CHECKERR: ^~~~~~~~~~~~~^ set -g PATH . echo banana > foobar foobar --banana # CHECKERR: checks/command-not-found.fish (line {{\d+}}): Unknown command. './foobar' exists but is not an executable file. # CHECKERR: foobar --banana -# CHECKERR: ^ +# CHECKERR: ^~~~~^ exit 0 diff --git a/tests/checks/vars_as_commands.fish b/tests/checks/vars_as_commands.fish index 405472e13..6ab3bdee0 100644 --- a/tests/checks/vars_as_commands.fish +++ b/tests/checks/vars_as_commands.fish @@ -47,4 +47,9 @@ echo 'echo foo; and $status' | $fish --no-config echo 'set -l status_cmd true; if $status_cmd; echo Heck yes this is true; end' | $fish --no-config #CHECK: Heck yes this is true +foo=bar $NONEXISTENT -c 'set foo 1 2 3; set --show foo' +#CHECKERR: {{.*}}checks/vars_as_commands.fish (line {{\d+}}): The expanded command was empty. +#CHECKERR: foo=bar $NONEXISTENT -c 'set foo 1 2 3; set --show foo' +#CHECKERR: ^~~~~~~~~~~^ + exit 0