44 "encoding/json"
55 "errors"
66 "fmt"
7+ "io"
78 "sort"
89 "strings"
910
@@ -138,6 +139,10 @@ func Wrap(msg string, args ...any) error {
138139/* LOGGING FUNCTIONS */
139140/* ------------------------------------------------------------------------- */
140141
142+ func mustWrite (w io.Writer , format string , args ... any ) {
143+ _ , _ = fmt .Fprintf (w , format , args ... )
144+ }
145+
141146// LogErrorChain logs an error chain to the console.
142147func LogErrorChain (err error ) {
143148 if err == nil {
@@ -147,9 +152,9 @@ func LogErrorChain(err error) {
147152 output := color .Output
148153 errorColor := color .New (color .FgRed , color .Bold ).SprintFunc ()
149154
150- fmt . Fprintf (output , "%s\n " , errorColor ("✘ Something went wrong:" ))
155+ mustWrite (output , "%s\n " , errorColor ("✘ Something went wrong:" ))
151156 for err != nil {
152- fmt . Fprintf (output , " %s %v\n " , errorColor ("→" ), err )
157+ mustWrite (output , " %s %v\n " , errorColor ("→" ), err )
153158 err = errors .Unwrap (err )
154159 }
155160}
@@ -160,21 +165,21 @@ func LogErrorChainWithAttrs(err error) {
160165 errorColor := color .New (color .FgRed , color .Bold ).SprintFunc ()
161166 argColor := color .New (color .Faint ).SprintFunc ()
162167
163- fmt . Fprintf (output , "%s\n " , errorColor ("✘ Something went wrong:" ))
168+ mustWrite (output , "%s\n " , errorColor ("✘ Something went wrong:" ))
164169 for err != nil {
165170 if tempoErr , ok := err .(* TempoError ); ok {
166- fmt . Fprintf (output , " - Code: %d, Message: %s\n " , tempoErr .Code , tempoErr .Message )
171+ mustWrite (output , " - Code: %d, Message: %s\n " , tempoErr .Code , tempoErr .Message )
167172 if len (tempoErr .Attrs ) > 0 {
168- fmt . Fprintf (output , " Attrs:\n " )
173+ mustWrite (output , " Attrs:\n " )
169174
170175 // Sort the metadata keys for consistent output
171176 keys := sortedKeys (tempoErr .Attrs )
172177 for _ , key := range keys {
173- fmt . Fprintf (output , " %s: %v\n " , argColor (key ), tempoErr .Attrs [key ])
178+ mustWrite (output , " %s: %v\n " , argColor (key ), tempoErr .Attrs [key ])
174179 }
175180 }
176181 } else {
177- fmt . Fprintf (output , " - %v\n " , err )
182+ mustWrite (output , " - %v\n " , err )
178183 }
179184 err = errors .Unwrap (err )
180185 }
0 commit comments