From c95a223f5ef2aa24939810090a0c9909d115b3aa Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 19 Apr 2021 16:47:17 +0200 Subject: [PATCH] Better errors when calling a command in a command substitution fails --- CHANGELOG.rst | 3 ++- src/expand.cpp | 9 +++++++++ tests/checks/switch.fish | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 95a8b210f..26db5dfe6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,7 +20,8 @@ Scripting improvements - ``echo`` no longer writes its output one byte at a time, improving performance and allowing use with linux' special API files (``/proc``, ``/sys`` and such) (:issue:`7836`). - fish should now better handle ``cd`` on filesystems with broken ``stat(3)`` responses (:issue:`7577`). - Builtins now properly report a ``$status`` of 1 upon unsuccessful writes (:issue:`7857`). -- `string match` with unmatched capture groups and without the `--all` flag now sets an empty variable instead of a variable containing the empty string, matching the documentation. +- ``string match`` with unmatched capture groups and without the ``--all`` flag now sets an empty variable instead of a variable containing the empty string, matching the documentation. +- Better errors when a command in a command substitution wasn't found or is not allowed. Interactive improvements ------------------------- diff --git a/src/expand.cpp b/src/expand.cpp index 04f15e846..10a3d88c4 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -652,6 +652,15 @@ static expand_result_t expand_cmdsubst(wcstring input, const operation_context_t case STATUS_CMD_ERROR: err = L"Too many active file descriptors"; break; + case STATUS_CMD_UNKNOWN: + err = L"Unknown command"; + break; + case STATUS_ILLEGAL_CMD: + err = L"Commandname was invalid"; + break; + case STATUS_NOT_EXECUTABLE: + err = L"Command not executable"; + break; default: err = L"Unknown error while evaluating command substitution"; break; diff --git a/tests/checks/switch.fish b/tests/checks/switch.fish index f0706867d..e8576fc02 100644 --- a/tests/checks/switch.fish +++ b/tests/checks/switch.fish @@ -100,3 +100,20 @@ switch $smurf echo Test 3 pass end #CHECK: Test 3 pass + +begin + set -l PATH + switch (doesnotexist) + case '*' + echo Matched! + end + # CHECKERR: fish: Unknown command: doesnotexist + # CHECKERR: checks/switch.fish (line {{\d+}}): + # CHECKERR: doesnotexist + # CHECKERR: ^ + # CHECKERR: in command substitution + # CHECKERR: {{\t}}called on line {{\d+}} of file checks/switch.fish + # CHECKERR: checks/switch.fish (line {{\d+}}): Unknown command + # CHECKERR: switch (doesnotexist) + # CHECKERR: ^ +end