mirror of https://github.com/coder/coder.git
chore: add validation errors to the cli output (#12814)
* chore: add validation errors to the cli output
This commit is contained in:
parent
94e82f9662
commit
5137433123
15
cli/root.go
15
cli/root.go
|
@ -1084,10 +1084,23 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str
|
|||
_, _ = str.WriteString("\n")
|
||||
}
|
||||
|
||||
// The main error message
|
||||
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), err.Message))
|
||||
|
||||
// Validation errors.
|
||||
if len(err.Validations) > 0 {
|
||||
_, _ = str.WriteString("\n")
|
||||
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), fmt.Sprintf("%d validation error(s) found", len(err.Validations))))
|
||||
for _, e := range err.Validations {
|
||||
_, _ = str.WriteString("\n\t")
|
||||
_, _ = str.WriteString(pretty.Sprint(cliui.DefaultStyles.Field, e.Field))
|
||||
_, _ = str.WriteString(pretty.Sprintf(cliui.DefaultStyles.Warn, ": %s", e.Detail))
|
||||
}
|
||||
}
|
||||
|
||||
if err.Helper != "" {
|
||||
_, _ = str.WriteString("\n")
|
||||
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), err.Helper))
|
||||
_, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), "Suggestion: %s", err.Helper))
|
||||
}
|
||||
// By default we do not show the Detail with the helper.
|
||||
if opts.Verbose || (err.Helper == "" && err.Detail != "") {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
Encountered an error running "coder exp example-error api", see "coder exp example-error api --help" for more information
|
||||
error: Top level sdk error message.
|
||||
Have you tried turning it off and on again?
|
||||
1 validation error(s) found
|
||||
region : magic dust is not available in your region
|
||||
Suggestion: Have you tried turning it off and on again?
|
||||
|
|
|
@ -4,4 +4,6 @@ error: 3 errors encountered: Trace=[wrapped: ])
|
|||
2. second error: function decided not to work, and it never will
|
||||
3. Trace=[wrapped api error: ]
|
||||
Top level sdk error message.
|
||||
1 validation error(s) found
|
||||
region : magic dust is not available in your region
|
||||
magic dust unavailable, please try again later
|
||||
|
|
Loading…
Reference in New Issue