Skip to content

Commit b57b7b7

Browse files
committed
chore: add validation errors to the cli output
1 parent 94e82f9 commit b57b7b7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cli/root.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,23 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str
10841084
_, _ = str.WriteString("\n")
10851085
}
10861086

1087+
// The main error message
10871088
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), err.Message))
1089+
1090+
// Validation errors.
1091+
if len(err.Validations) > 0 {
1092+
_, _ = str.WriteString("\n")
1093+
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), fmt.Sprintf("%d validation error(s) found", len(err.Validations))))
1094+
for _, e := range err.Validations {
1095+
_, _ = str.WriteString("\n\t")
1096+
_, _ = str.WriteString(pretty.Sprint(cliui.DefaultStyles.Field, e.Field))
1097+
_, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), ":%s", e.Detail))
1098+
}
1099+
}
1100+
10881101
if err.Helper != "" {
10891102
_, _ = str.WriteString("\n")
1090-
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), err.Helper))
1103+
_, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), "Suggestion: %s", err.Helper))
10911104
}
10921105
// By default we do not show the Detail with the helper.
10931106
if opts.Verbose || (err.Helper == "" && err.Detail != "") {

0 commit comments

Comments
 (0)