From 279e97d709a3cab19818ae604081b00da6100883 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Fri, 6 Oct 2023 13:57:08 -0700 Subject: [PATCH] Handle user facing errors with structured output --- pkg/cmdlets/errors/errors.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/cmdlets/errors/errors.go b/pkg/cmdlets/errors/errors.go index 02816023fc..6eccbf50aa 100644 --- a/pkg/cmdlets/errors/errors.go +++ b/pkg/cmdlets/errors/errors.go @@ -87,7 +87,14 @@ func (o *OutputError) MarshalOutput(f output.Format) interface{} { } func (o *OutputError) MarshalStructured(f output.Format) interface{} { - return output.StructuredError{locale.JoinedErrorMessage(o.error)} + var userFacingError errs.UserFacingError + var message string + if errors.As(o.error, &userFacingError) { + message = userFacingError.UserError() + } else { + message = locale.JoinedErrorMessage(o.error) + } + return output.StructuredError{message} } func trimError(msg string) string {