aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--assert/errequal.go4
-rw-r--r--assert/errequal_test.go14
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 47bb9a4..58b4e44 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,12 @@ SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
SPDX-License-Identifier: Apache-2.0
-->
+# v1.10.1 (TBD)
+
+Changes:
+
+- Fix a panic in assert.ErrEqual when the `expected` argument is an error whose underlying type is a struct type.
+
# v1.10.0 (2026-06-20)
Changes:
diff --git a/assert/errequal.go b/assert/errequal.go
index 4752f26..86cd719 100644
--- a/assert/errequal.go
+++ b/assert/errequal.go
@@ -21,7 +21,9 @@ func ErrEqual(t TestingTB, actual error, expected any) bool {
// and also coerce all nil values of concrete `error` types into untyped nil
if expectedErr, ok := expected.(error); ok {
// convert nil values of concrete error types into a generic nil value
- if reflect.ValueOf(expectedErr).IsNil() {
+ expectedValue := reflect.ValueOf(expectedErr)
+ kind := expectedValue.Kind()
+ if (kind == reflect.Pointer || kind == reflect.Interface) && expectedValue.IsNil() {
expected = nil
} else {
expected = expectedErr
diff --git a/assert/errequal_test.go b/assert/errequal_test.go
index 5efbdc5..4bb9080 100644
--- a/assert/errequal_test.go
+++ b/assert/errequal_test.go
@@ -74,4 +74,18 @@ func TestErrEqual(t *testing.T) {
Outcome: testcapture.OutcomePanicked,
Panic: "cannot handle `expected` of type int",
})
+
+ // an earlier version had a bug because this call caused reflect.Value.IsNil() to be called on a value of kind Struct
+ expectErrors(t, func(t assert.TestingTB) {
+ assert.ErrEqual(t, nil, structTypedError{"foo"})
+ }, `expected "foo", but got no error`)
+}
+
+type structTypedError struct {
+ Message string
+}
+
+// Error implements the builtin/error interface.
+func (e structTypedError) Error() string {
+ return e.Message
}