From cfecc4cc35e25f6876ed9c8451f67aabbb860b95 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 14 Sep 2022 17:55:18 +0200 Subject: [PATCH] command_not_found: Add special error for ENOTDIR --- src/parse_execution.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 09a7e4757..945c3380a 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -735,9 +735,23 @@ end_execution_reason_t parse_execution_context_t::handle_command_not_found( // but this mainly applies to EACCES. We could also feasibly get: // ELOOP // ENAMETOOLONG + if (err_code == ENOTDIR) { + // If the original command did not include a "/", assume we found it via $PATH. + auto src = get_source(statement.command); + if (src.find(L"/") == wcstring::npos) { + return this->report_error( + STATUS_NOT_EXECUTABLE, statement.command, + _(L"Unknown command. A component of '%ls' is not a directory. Check your $PATH."), cmd); + } else { + return this->report_error( + STATUS_NOT_EXECUTABLE, statement.command, + _(L"Unknown command. A component of '%ls' is not a directory."), cmd); + } + } + return this->report_error( - STATUS_NOT_EXECUTABLE, statement.command, - _(L"Unknown command. '%ls' exists but is not an executable file."), cmd); + STATUS_NOT_EXECUTABLE, statement.command, + _(L"Unknown command. '%ls' exists but is not an executable file."), cmd); } // Handle unrecognized commands with standard command not found handler that can make better