Skip to content

chore: handle errors in wsproxy server for cli using buildinfo #11584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Correct return boolean
  • Loading branch information
Emyrk committed Jan 11, 2024
commit a84f368b3938c6a20a9c16235b9b7948c4da1dbc
15 changes: 10 additions & 5 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,21 +1055,21 @@ func cliHumanFormatError(err error, opts *formatOpts) (string, bool) {
// Format as a single error
return cliHumanFormatError(multiErrors[0], opts)
}
return formatMultiError(multiErrors, opts), false
return formatMultiError(multiErrors, opts), true
}

// First check for sentinel errors that we want to handle specially.
// Order does matter! We want to check for the most specific errors first.
//var sdkError *codersdk.Error
//if errors.As(err, &sdkError) {
if sdkError, ok := err.(*codersdk.Error); ok {
return formatCoderSDKError(sdkError, opts), false
return formatCoderSDKError(sdkError, opts), true
}

//var cmdErr *clibase.RunCommandError
//if errors.As(err, &cmdErr) {
if cmdErr, ok := err.(*clibase.RunCommandError); ok {
return formatRunCommandError(cmdErr, opts), false
return formatRunCommandError(cmdErr, opts), true
}

uw, ok := err.(interface{ Unwrap() error })
Expand Down Expand Up @@ -1138,9 +1138,14 @@ func formatRunCommandError(err *clibase.RunCommandError, opts *formatOpts) strin
var str strings.Builder
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), fmt.Sprintf("Encountered an error running %q", err.Cmd.FullName())))

msgString, _ := cliHumanFormatError(err.Err, opts)
msgString, special := cliHumanFormatError(err.Err, opts)
_, _ = str.WriteString("\n")
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), msgString))
if special {
_, _ = str.WriteString(msgString)
} else {
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), msgString))
}

return str.String()
}

Expand Down