From b57b7b72cb4020d96f15023f713bf0f738d43046 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 28 Mar 2024 14:54:23 -0500 Subject: [PATCH 1/4] chore: add validation errors to the cli output --- cli/root.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index 83367169df154..e04cfaa5c5863 100644 --- a/cli/root.go +++ b/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(tailLineStyle(), ":%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 != "") { From 92bfa0dfaaea1040fe16e695a65497603471454e Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 28 Mar 2024 14:59:07 -0500 Subject: [PATCH 2/4] add a space: --- cli/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index e04cfaa5c5863..05de673c6a5bf 100644 --- a/cli/root.go +++ b/cli/root.go @@ -1094,7 +1094,7 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str for _, e := range err.Validations { _, _ = str.WriteString("\n\t") _, _ = str.WriteString(pretty.Sprint(cliui.DefaultStyles.Field, e.Field)) - _, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), ":%s", e.Detail)) + _, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), ": %s", e.Detail)) } } From 13bd16797948e433d2276ed0b401e0e30dafd9e3 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Fri, 29 Mar 2024 09:03:18 -0500 Subject: [PATCH 3/4] make field output yellow --- cli/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/root.go b/cli/root.go index 05de673c6a5bf..d9407cf21766c 100644 --- a/cli/root.go +++ b/cli/root.go @@ -1094,7 +1094,7 @@ func formatCoderSDKError(from string, err *codersdk.Error, opts *formatOpts) str for _, e := range err.Validations { _, _ = str.WriteString("\n\t") _, _ = str.WriteString(pretty.Sprint(cliui.DefaultStyles.Field, e.Field)) - _, _ = str.WriteString(pretty.Sprintf(tailLineStyle(), ": %s", e.Detail)) + _, _ = str.WriteString(pretty.Sprintf(cliui.DefaultStyles.Warn, ": %s", e.Detail)) } } From af4953c15b6c986b9cae451d1a9e155a968fb814 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 2 Apr 2024 09:44:57 -0500 Subject: [PATCH 4/4] update golden fils --- cli/testdata/coder_exp_example-error_api.golden | 4 +++- cli/testdata/coder_exp_example-error_multi-error.golden | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/testdata/coder_exp_example-error_api.golden b/cli/testdata/coder_exp_example-error_api.golden index e15b60abbd3d5..a0a8455447b74 100644 --- a/cli/testdata/coder_exp_example-error_api.golden +++ b/cli/testdata/coder_exp_example-error_api.golden @@ -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? diff --git a/cli/testdata/coder_exp_example-error_multi-error.golden b/cli/testdata/coder_exp_example-error_multi-error.golden index 73a32afd8006c..2b89275dffc57 100644 --- a/cli/testdata/coder_exp_example-error_multi-error.golden +++ b/cli/testdata/coder_exp_example-error_multi-error.golden @@ -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