From a61505f1a562a8f938e7c0cf42d7b00b9893276a Mon Sep 17 00:00:00 2001 From: Ivan Sopov Date: Mon, 3 Jul 2023 19:19:16 +0300 Subject: [PATCH] fix unwrap on typed nil --- error.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/error.go b/error.go index 7cca0b8..802ce70 100644 --- a/error.go +++ b/error.go @@ -160,7 +160,7 @@ func (e *Error) Is(target error) bool { // Unwrap returns cause of current error in case it is wrapped transparently, nil otherwise. // See also: errors.Unwrap() func (e *Error) Unwrap() error { - if e.cause != nil && e.transparent { + if e != nil && e.cause != nil && e.transparent { return e.cause } else { return nil @@ -170,9 +170,9 @@ func (e *Error) Unwrap() error { // Format implements the Formatter interface. // Supported verbs: // -// %s simple message output -// %v same as %s -// %+v full output complete with a stack trace +// %s simple message output +// %v same as %s +// %+v full output complete with a stack trace // // In is nearly always preferable to use %+v format. // If a stack trace is not required, it should be omitted at the moment of creation rather in formatting.