File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,23 @@ func (e *ErrorX) SetAttr(s ...slog.Attr) *ErrorX {
313313
314314// parseError recursively parses all known types of errors
315315func parseError (to * ErrorX , err error ) {
316+ // guard against panics in external libraries calls
317+ defer func () {
318+ if r := recover (); r != nil {
319+ // Convert panic to error and append it as the last error
320+ var panicErr error
321+ switch v := r .(type ) {
322+ case error :
323+ panicErr = fmt .Errorf ("error while unwrapping: %w" , v )
324+ case string :
325+ panicErr = fmt .Errorf ("error while unwrapping: %s" , v )
326+ default :
327+ panicErr = fmt .Errorf ("error while unwrapping: panic: %v" , r )
328+ }
329+ to .append (panicErr )
330+ }
331+ }()
332+
316333 if err == nil {
317334 return
318335 }
@@ -393,7 +410,7 @@ func parseError(to *ErrorX, err error) {
393410 parseError (to , errors .New (part ))
394411 }
395412 } else {
396- // this cannot be furthur unwrapped
413+ // this cannot be further unwrapped
397414 to .append (err )
398415 }
399416 }
You can’t perform that action at this time.
0 commit comments