Fixed a potential NPE when printing error cause chains.
This commit is contained in:
parent
325901c2c3
commit
9803f7f9f3
|
@ -176,7 +176,12 @@ func ErrorWithCauseChain(err error) string {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer.WriteString(err.Error())
|
|
||||||
|
if err != nil {
|
||||||
|
buffer.WriteString(err.Error())
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("<err=nil>")
|
||||||
|
}
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ caused by AssertionError: err2
|
||||||
caused by err3`
|
caused by err3`
|
||||||
|
|
||||||
assert.Equal(t, expected, ErrorWithCauseChain(err))
|
assert.Equal(t, expected, ErrorWithCauseChain(err))
|
||||||
|
|
||||||
|
assert.Equal(t, "<err=nil>", ErrorWithCauseChain(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCombineErrors(t *testing.T) {
|
func TestCombineErrors(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue