Skip to content

Commit c68f826

Browse files
committed
fix(cli): fix potential panic in traceError if unwrapped err is nil
1 parent c5a4095 commit c68f826

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cli/root.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,16 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str
11161116
//nolint:errorlint
11171117
func traceError(err error) string {
11181118
if uw, ok := err.(interface{ Unwrap() error }); ok {
1119-
a, b := err.Error(), uw.Unwrap().Error()
1119+
var a, b string
1120+
if err != nil {
1121+
a = err.Error()
1122+
}
1123+
if uw != nil {
1124+
uwerr := uw.Unwrap()
1125+
if uwerr != nil {
1126+
b = uwerr.Error()
1127+
}
1128+
}
11201129
c := strings.TrimSuffix(a, b)
11211130
return c
11221131
}

0 commit comments

Comments
 (0)