mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix(cli): handle nil unwrap errors when formatting (#18099)
Discovered an unhelpful error when running a CLI command without internet (I didn't know I didn't have internet!): ``` $ coder ls Encountered an error running "coder list", see "coder list --help" for more information error: <nil> ``` The source of this was that calling `Unwrap()` on `net.DNSError` can return nil, causing the whole error trace to get replaced by it. Instead, we'll just treat a nil `Unwrap()` return value as if there was nothing to unwrap. The result is: ``` $ coder ls Encountered an error running "coder list", see "coder list --help" for more information error: query workspaces: Get "https://dev.coder.com/api/v2/workspaces?q=owner%3Ame": dial tcp: lookup dev.coder.com: no such host ```
This commit is contained in:
@ -1060,13 +1060,14 @@ func cliHumanFormatError(from string, err error, opts *formatOpts) (string, bool
|
|||||||
return formatRunCommandError(cmdErr, opts), true
|
return formatRunCommandError(cmdErr, opts), true
|
||||||
}
|
}
|
||||||
|
|
||||||
uw, ok := err.(interface{ Unwrap() error })
|
if uw, ok := err.(interface{ Unwrap() error }); ok {
|
||||||
if ok {
|
if unwrapped := uw.Unwrap(); unwrapped != nil {
|
||||||
msg, special := cliHumanFormatError(from+traceError(err), uw.Unwrap(), opts)
|
msg, special := cliHumanFormatError(from+traceError(err), unwrapped, opts)
|
||||||
if special {
|
if special {
|
||||||
return msg, special
|
return msg, special
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// If we got here, that means that the wrapped error chain does not have
|
// If we got here, that means that the wrapped error chain does not have
|
||||||
// any special formatting below it. So we want to return the topmost non-special
|
// any special formatting below it. So we want to return the topmost non-special
|
||||||
// error (which is 'err')
|
// error (which is 'err')
|
||||||
|
Reference in New Issue
Block a user