Skip to content

Commit 3186843

Browse files
committed
chore: add validation errors to the cli output
1 parent b785e99 commit 3186843

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
@@ -1076,10 +1076,23 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str
10761076
_, _ = str.WriteString("\n")
10771077
}
10781078

1079+
// The main error message
10791080
_, _ = str.WriteString(pretty.Sprint(headLineStyle(), err.Message))
1081+
1082+
// Validation errors.
1083+
if len(err.Validations) > 0 {
1084+
_, _ = str.WriteString("\n")
1085+
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), fmt.Sprintf("%d validation error(s) found", len(err.Validations))))
1086+
for _, e := range err.Validations {
1087+
_, _ = str.WriteString("\n\t")
1088+
_, _ = str.WriteString(pretty.Sprint(cliui.DefaultStyles.Field, e.Field))
1089+
_, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), ":%s", e.Detail))
1090+
}
1091+
}
1092+
10801093
if err.Helper != "" {
10811094
_, _ = str.WriteString("\n")
1082-
_, _ = str.WriteString(pretty.Sprint(tailLineStyle(), err.Helper))
1095+
_, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), "Suggestion: %s", err.Helper))
10831096
}
10841097
// By default we do not show the Detail with the helper.
10851098
if opts.Verbose || (err.Helper == "" && err.Detail != "") {

0 commit comments

Comments
 (0)