Skip to content

Commit db7b08e

Browse files
committed
DetailedError will not panic on nil error
1 parent 5acca95 commit db7b08e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

debug_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ func TestDetailedError(t *testing.T) {
100100
}
101101
}
102102
}
103+
104+
func TestNilDetailedError(t *testing.T) {
105+
t.Parallel()
106+
var err error
107+
require.NoError(t, err, DetailedError(err))
108+
}

error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func (ne *njectError) Error() string {
1919
// or something that called Bind() then it will return
2020
// a much more detailed error than just calling err.Error()
2121
func DetailedError(err error) string {
22+
if err == nil {
23+
return ""
24+
}
2225
var njectError *njectError
2326
if errors.As(err, &njectError) {
2427
dups := duplicateTypes()

0 commit comments

Comments
 (0)