From e7b4f5344efaf996f7047f66d4c4b63253179caa Mon Sep 17 00:00:00 2001 From: Foil-hat-guy Date: Mon, 5 May 2025 01:22:01 +0300 Subject: [PATCH] Test if Unwrap method is supported is added. --- error.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 {