go: runtime: wrong Unix error code from panic.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version devel +baf3eb1625 Tue Mar 6 01:11:26 2018 +0000 darwin/amd64
% cat p.go
package main
func main() {
panic(3)
}
% ./p
panic: 3
goroutine 1 [running]:
main.main()
/Users/r/p.go:4 +0x39
% echo $?
2
%
Exit code 2 traditionally means ‘incorrect arguments’, as in flag.Usage.
Panic should be something like 127 or 255 on Unix.
Reported by darren.e.grant@gmail.com on nuts.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 6
- Comments: 15 (8 by maintainers)
Exit status 127 is used by the shell to indicate “command not found.” Exit status 126 is used by the shell to indicate “command found but not executable.” Exit status values 128 and up are used by the shell to indicate exiting due to a signal.
If a C++ program exits due to an uncaught
throw
it raisesSIGABRT
and therefore exits with status 134 (on GNU/Linux).If a Python program exits due to raising an exception, it exits with status 1.
I think we should change an unrecovered
panic
to exit with status 1 rather than 2. And we should document in the language spec that an uncaughtpanic
will cause the program to exit with a non-zero exit status, but we shouldn’t document it further.