mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Log original exit code used when a builtin returns a negative exit code
This commit is contained in:
parent
0e4d088b11
commit
b91723dab6
2 changed files with 5 additions and 5 deletions
|
@ -475,13 +475,13 @@ proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_stre
|
|||
return proc_status_t::empty();
|
||||
}
|
||||
if (code < 0) {
|
||||
FLOGF(warning, "builtin %ls returned invalid exit code %d", cmdname.c_str(), code);
|
||||
// If the code is below 0, constructing a proc_status_t
|
||||
// would assert() out, which is a terrible failure mode
|
||||
// So instead, what we do is we get a positive code,
|
||||
// and we avoid 0.
|
||||
code = abs((256 + code) % 256);
|
||||
if (code == 0) code = 255;
|
||||
FLOGF(warning, "builtin %ls returned invalid exit code %d", cmdname.c_str(), code);
|
||||
}
|
||||
return proc_status_t::from_exit_code(code);
|
||||
}
|
||||
|
|
|
@ -26,22 +26,22 @@ echo $status
|
|||
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
||||
|
||||
$fish -c 'exit -5'
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code 251
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code -5
|
||||
echo $status
|
||||
# CHECK: 251
|
||||
|
||||
$fish -c 'exit -1'
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code -1
|
||||
echo $status
|
||||
# CHECK: 255
|
||||
|
||||
# (we avoid 0, so this is turned into 255 again)
|
||||
$fish -c 'exit -256'
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code -256
|
||||
echo $status
|
||||
# CHECK: 255
|
||||
|
||||
$fish -c 'exit -512'
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code 255
|
||||
# CHECKERR: warning: builtin exit returned invalid exit code -512
|
||||
echo $status
|
||||
# CHECK: 255
|
||||
|
|
Loading…
Reference in a new issue