@@ -824,53 +824,50 @@ type prettyErrorFormatter struct {
824
824
825
825
func (p * prettyErrorFormatter ) format (err error ) {
826
826
if err == nil {
827
- // 🍒
827
+ // 🏁
828
828
p .printf ("\n " )
829
829
return
830
830
}
831
831
832
- underErr := errors .Unwrap (err )
832
+ nextErr := errors .Unwrap (err )
833
833
834
834
//nolint:errorlint
835
- if _ , ok := err .(* clibase.RunCommandError ); ok && p .level == 0 && underErr != nil {
836
- // We can do a better job now .
837
- p .format (underErr )
835
+ if _ , ok := err .(* clibase.RunCommandError ); ok && p .level == 0 && nextErr != nil {
836
+ // Avoid extra nesting .
837
+ p .format (nextErr )
838
838
return
839
839
}
840
840
841
- errorWithoutChildren := err .Error ()
842
- if underErr != nil {
843
- errorWithoutChildren = strings .TrimSuffix (err .Error (), ": " + underErr .Error ())
841
+ var headErr string
842
+ if nextErr != nil {
843
+ headErr = strings .TrimSuffix (err .Error (), ": " + nextErr .Error ())
844
+ } else {
845
+ headErr = err .Error ()
844
846
}
845
847
846
- // Format the root error specially since it's the most relevant.
847
- if p .level == 0 {
848
- textStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#D16644" )).Bold (false )
849
- var msg string
850
- var sdkError * codersdk.Error
851
- if errors .As (err , & sdkError ) {
852
- msg = sdkError .Message + sdkError .Helper
853
- } else {
854
- msg = errorWithoutChildren
855
- }
856
- p .printf (
857
- "%s" ,
858
- textStyle .Render (msg ),
859
- )
848
+ var msg string
849
+ var sdkError * codersdk.Error
850
+ if errors .As (err , & sdkError ) {
851
+ msg = sdkError .Message + sdkError .Helper
852
+ } else {
853
+ msg = headErr
854
+ }
860
855
861
- p . level ++
862
- p . format ( underErr )
863
- return
856
+ textStyle := lipgloss . NewStyle (). Foreground ( lipgloss . Color ( "#D16644" ))
857
+ if p . level > 0 {
858
+ textStyle . Foreground ( lipgloss . Color ( "#969696" ))
864
859
}
865
860
866
- textStyle := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#969696" )).Bold (false )
861
+ if nextErr != nil {
862
+ msg = msg + ": "
863
+ }
867
864
868
865
p .printf (
869
866
"%s" ,
870
- textStyle .Render (": " + errorWithoutChildren ),
867
+ textStyle .Render (msg ),
871
868
)
872
869
p .level ++
873
- p .format (underErr )
870
+ p .format (nextErr )
874
871
}
875
872
876
873
func (p * prettyErrorFormatter ) printf (format string , a ... interface {}) {
0 commit comments