@@ -10,33 +10,24 @@ import (
1010func errorsWithError (e Entry , err error ) Entry {
1111 ne := newEntry (e )
1212
13- if w , ok := err .(* errors.Wrapped ); ok {
14- cause := errors .Cause (w ).(* errors.Wrapped )
13+ switch t := err .(type ) {
14+ case errors.Chain :
15+ cause := t [0 ]
1516 ne .Fields = append (ne .Fields , Field {Key : "error" , Value : fmt .Sprintf ("%s: %s" , cause .Prefix , cause .Err )})
1617 ne .Fields = append (ne .Fields , Field {Key : "source" , Value : cause .Source })
17- if len (w .Errors ) > 0 {
18- // top level error
19- types := make ([]string , 0 , len (w .Errors ))
20- for _ , e := range w .Errors {
21- for _ , tag := range e .Tags {
22- ne .Fields = append (ne .Fields , Field {Key : tag .Key , Value : tag .Value })
23- }
24- types = append (types , e .Types ... )
25- }
26- if len (types ) > 0 {
27- ne .Fields = append (ne .Fields , Field {Key : "types" , Value : strings .Join (types , "," )})
28- }
29- } else {
30- // not top level, probably cause
31- for _ , tag := range w .Tags {
18+
19+ types := make ([]string , 0 , len (t ))
20+ for _ , e := range t {
21+ for _ , tag := range e .Tags {
3222 ne .Fields = append (ne .Fields , Field {Key : tag .Key , Value : tag .Value })
3323 }
34- if len (w .Types ) > 0 {
35- ne .Fields = append (ne .Fields , Field {Key : "types" , Value : strings .Join (w .Types , "," )})
36- }
24+ types = append (types , e .Types ... )
25+ }
26+ if len (types ) > 0 {
27+ ne .Fields = append (ne .Fields , Field {Key : "types" , Value : strings .Join (types , "," )})
3728 }
3829
39- } else {
30+ default :
4031 ne .Fields = append (ne .Fields , Field {Key : "error" , Value : err .Error ()})
4132 frame := errors .StackLevel (2 )
4233 name := fmt .Sprintf ("%n" , frame )
0 commit comments