src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/diag/show_error.go (about) 1 package diag 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 // ShowError shows an error. It uses the Show method if the error 9 // implements Shower. Otherwise, it prints the error in bold and red, with a 10 // trailing newline. 11 func ShowError(w io.Writer, err error) { 12 if shower, ok := err.(Shower); ok { 13 fmt.Fprintln(w, shower.Show("")) 14 } else { 15 fmt.Fprintf(w, "\033[31;1m%s\033[m\n", err.Error()) 16 } 17 }