diff --git a/error.go b/error.go index 4127374..2ace8e1 100644 --- a/error.go +++ b/error.go @@ -4,8 +4,25 @@ import( "fmt" ) +type unwraperr interface { + Unwrap() error +} + +type unwraperrs interface { + Unwrap() []error +} + +func isUnwrapable(err error) bool { + _, ok1 := err.(unwraperr) + _, ok2 := err.(unwraperrs) + return ok1 || ok2 +} + func errStack(err1 error, err2 error) error { - return fmt.Errorf("%w: %w", err1, err2) + if isUnwrapable(err2) { + return fmt.Errorf("%w: %w", err1, err2) + } + return fmt.Errorf("%w: %v", err1, err2) } func ERR_NOT_TTY() error {