You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// StatusError should only be used for errors, and all errors should
73
-
// have a non-zero exit status, so never exit with 0
74
-
ifsterr.StatusCode==0 {
75
-
os.Exit(1)
86
+
os.Exit(getExitCode(err))
87
+
}
88
+
// Keep CI happy, which expects a newline to be printed when terminated.
89
+
_, _=fmt.Fprintln(cmd.Out())
90
+
}
91
+
92
+
// getExitCode returns the exit-code to use for the given error.
93
+
// If err is a [cli.StatusError] and has a StatusCode set, it uses the
94
+
// status-code from it, otherwise it returns "1" for any error.
95
+
funcgetExitCode(errerror) int {
96
+
iferr==nil {
97
+
return0
98
+
}
99
+
100
+
varuserTerminatedErrerrCtxSignalTerminated
101
+
iferrors.As(err, &userTerminatedErr) {
102
+
s, ok:=userTerminatedErr.signal.(syscall.Signal)
103
+
if!ok {
104
+
return1
76
105
}
77
-
os.Exit(sterr.StatusCode)
106
+
return128+int(s)
107
+
}
108
+
109
+
varstErr cli.StatusError
110
+
iferrors.As(err, &stErr) &&stErr.StatusCode!=0 { // FIXME(thaJeztah): StatusCode should never be used with a zero status-code. Check if we do this anywhere.
111
+
returnstErr.StatusCode
78
112
}
79
113
80
-
os.Exit(1)
114
+
// No status-code provided; all errors should have a non-zero exit code.
0 commit comments