@@ -818,57 +818,57 @@ func isConnectionError(err error) bool {
818
818
}
819
819
820
820
type prettyErrorFormatter struct {
821
- level int
822
- w io.Writer
821
+ w io.Writer
823
822
}
824
823
825
824
func (p * prettyErrorFormatter ) format (err error ) {
826
- if err == nil {
827
- // 🏁
828
- p .printf ("\n " )
829
- return
830
- }
831
-
832
- nextErr := errors .Unwrap (err )
825
+ errTail := errors .Unwrap (err )
833
826
834
827
//nolint:errorlint
835
- if _ , ok := err .(* clibase.RunCommandError ); ok && p . level == 0 && nextErr != nil {
828
+ if _ , ok := err .(* clibase.RunCommandError ); ok && errTail != nil {
836
829
// Avoid extra nesting.
837
- p .format (nextErr )
830
+ p .format (errTail )
838
831
return
839
832
}
840
833
841
834
var headErr string
842
- if nextErr != nil {
843
- headErr = strings .TrimSuffix (err .Error (), ": " + nextErr .Error ())
835
+ if errTail != nil {
836
+ headErr = strings .TrimSuffix (err .Error (), ": " + errTail .Error ())
844
837
} else {
845
838
headErr = err .Error ()
846
839
}
847
840
848
841
var msg string
849
842
var sdkError * codersdk.Error
850
843
if errors .As (err , & sdkError ) {
851
- msg = sdkError .Message + sdkError .Helper
844
+ // We don't want to repeat the same error message twice, so we
845
+ // only show the SDK error on the top of the stack.
846
+ msg = sdkError .Message
847
+ if sdkError .Helper != "" {
848
+ msg = msg + "\n " + sdkError .Helper
849
+ }
850
+ // The SDK error is usually good enough, and we don't want to overwhelm
851
+ // the user with output.
852
+ errTail = nil
852
853
} else {
853
854
msg = headErr
854
855
}
855
856
856
857
textStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#D16644" ))
857
- if p .level > 0 {
858
- // Grey out the less important, deep errors.
859
- textStyle .Foreground (lipgloss .Color ("#969696" ))
860
- }
861
-
862
- if nextErr != nil {
858
+ if errTail != nil {
863
859
msg = msg + ": "
864
860
}
865
-
866
861
p .printf (
867
862
"%s" ,
868
863
textStyle .Render (msg ),
869
864
)
870
- p .level ++
871
- p .format (nextErr )
865
+
866
+ if errTail != nil {
867
+ // Grey out the less important, deep errors.
868
+ textStyle .Foreground (lipgloss .Color ("#969696" ))
869
+ p .printf ("%s" , textStyle .Render (errTail .Error ()))
870
+ }
871
+ p .printf ("\n " )
872
872
}
873
873
874
874
func (p * prettyErrorFormatter ) printf (format string , a ... interface {}) {
0 commit comments