mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Propagate command-not-found errors when invoking wrapped commands
Before this change, if a package manager was not installed, safe-chain still sets the function and when invoked, the wrapper will invoke safe-chain, which will exit with error code 127 when it fails to invoke the wrapped command. As an example (with a shell prompt that shows $? when non-zero): ``` $ type -f pip bash: type: pip: not found 1$ pip 127$ ``` With this patch, the wrapper first checks for the existence of the wrapped command (ignoring functions), and if no such command exists, it instructs the shell to invoke it anyway. This results in the shell failing to find the command, and reporting an error as if the wrapper function wasn't there: ``` $ source init-posix.sh $ type -f pip bash: type: pip: not found 1$ pip Command 'pip' not found, but can be installed with: sudo apt install python3-pip 127$ ```
This commit is contained in:
parent
20cc62d6e1
commit
607b4ee87d
1 changed files with 8 additions and 0 deletions
|
|
@ -76,6 +76,14 @@ function printSafeChainWarning() {
|
|||
function wrapSafeChainCommand() {
|
||||
local original_cmd="$1"
|
||||
|
||||
if ! type -f "${original_cmd}" > /dev/null 2>&1; then
|
||||
# If the original command is not available, don't try to wrap it: invoke it
|
||||
# transparently, so the shell can report errors as if this wrapper didn't
|
||||
# exist.
|
||||
command $@
|
||||
return $?
|
||||
fi
|
||||
|
||||
if command -v safe-chain > /dev/null 2>&1; then
|
||||
# If the aikido command is available, just run it with the provided arguments
|
||||
safe-chain "$@"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue