github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/process/exit_code.go (about) 1 package process 2 3 import ( 4 "os" 5 ) 6 7 const ( 8 // posixShellInvalidCommandExitCode is the exit code returned by most (all?) 9 // POSIX shells when the provided command is invalid, e.g. due to an file 10 // without executable permissions. It seems to have originated with the 11 // Bourne shell and then been brought over to bash, zsh, and others. It 12 // doesn't seem to have a corresponding errno value, which I guess makes 13 // sense since errno values aren't generally expected to be used as exit 14 // codes, so we have to define it manually. 15 // TODO: Figure out if other shells return different exit codes when a 16 // command isn't found. Is this exit code defined in a standard somewhere? 17 posixShellInvalidCommandExitCode = 126 18 19 // posixShellCommandNotFoundExitCode is the exit code returned by most 20 // (all?) POSIX shells when the provided command isn't found. It seems to 21 // have originated with the Bourne shell and then been brought over to bash, 22 // zsh, and others. It doesn't seem to have a corresponding errno value, 23 // which I guess makes sense since errno values aren't generally expected to 24 // be used as exit codes, so we have to define it manually. 25 // TODO: Figure out if other shells return different exit codes when a 26 // command isn't found. Is this exit code defined in a standard somewhere? 27 posixShellCommandNotFoundExitCode = 127 28 ) 29 30 // IsPOSIXShellInvalidCommand returns whether or not a process state represents 31 // an "invalid" error from a POSIX shell. 32 func IsPOSIXShellInvalidCommand(state *os.ProcessState) bool { 33 return state.ExitCode() == posixShellInvalidCommandExitCode 34 } 35 36 // IsPOSIXShellCommandNotFound returns whether or not a process state represents 37 // a "command not found" error from a POSIX shell. 38 func IsPOSIXShellCommandNotFound(state *os.ProcessState) bool { 39 return state.ExitCode() == posixShellCommandNotFoundExitCode 40 }