feat: print command errors via hook

this allows users to remove the handlers and print
a custom message to their liking
pull/215/merge
sammyette 2022-12-13 12:57:27 -04:00
parent 6ca36847f1
commit 0a49e1a4ef
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 10 additions and 2 deletions

View File

@ -141,9 +141,9 @@ func runInput(input string, priv bool) {
if err != nil { if err != nil {
if exErr, ok := isExecError(err); ok { if exErr, ok := isExecError(err); ok {
hooks.Emit("command." + exErr.typ, exErr.cmd) hooks.Emit("command." + exErr.typ, exErr.cmd)
err = exErr.sprint() } else {
fmt.Fprintln(os.Stderr, err)
} }
fmt.Fprintln(os.Stderr, err)
} }
cmdFinish(exitCode, input, priv) cmdFinish(exitCode, input, priv)
} }

View File

@ -69,3 +69,11 @@ end
bait.catch('error', function(event, handler, err) bait.catch('error', function(event, handler, err)
bait.release(event, handler) bait.release(event, handler)
end) end)
bait.catch('command.not-found', function(cmd)
print(string.format('hilbish: %s not found', cmd))
end)
bait.catch('command.not-executable', function(cmd)
print(string.format('hilbish: %s: not executable', cmd))
end)