From def7dda8d9c9883f8a7bf6dcabd189b070f143a9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 7 Aug 2025 15:56:29 +0200 Subject: [PATCH] fix nil err --- exception.go | 3 +++ exception_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/exception.go b/exception.go index e4aacf4..09734c9 100644 --- a/exception.go +++ b/exception.go @@ -31,6 +31,9 @@ func (ex *custom) With(innerErr ...error) Custom { } func (ex *custom) IsSameAs(err error) bool { + if err == nil { + return false + } return strings.HasPrefix(err.Error(), fmt.Sprintf("[%s]:", ex.message)) } diff --git a/exception_test.go b/exception_test.go index eae5ae5..fb7d94c 100644 --- a/exception_test.go +++ b/exception_test.go @@ -46,6 +46,7 @@ func (suite *CustomExceptionTestSuite) TestShouldCompareExceptions() { suite.False(NotFoundException.IsSameAs(InvalidArgumentException)) suite.False(NotFoundException.IsSameAs(customErr)) suite.False(InvalidArgumentException.IsSameAs(customErr)) + suite.False(InvalidArgumentException.IsSameAs(nil)) } func TestCustomExceptionTestSuite(t *testing.T) {