Fixed a potential NPE when printing error cause chains.

This commit is contained in:
Zach Klippenstein 2015-12-30 01:56:50 -08:00
parent 325901c2c3
commit 9803f7f9f3
2 changed files with 8 additions and 1 deletions

View file

@ -176,7 +176,12 @@ func ErrorWithCauseChain(err error) string {
break
}
}
buffer.WriteString(err.Error())
if err != nil {
buffer.WriteString(err.Error())
} else {
buffer.WriteString("<err=nil>")
}
return buffer.String()
}

View file

@ -23,6 +23,8 @@ caused by AssertionError: err2
caused by err3`
assert.Equal(t, expected, ErrorWithCauseChain(err))
assert.Equal(t, "<err=nil>", ErrorWithCauseChain(nil))
}
func TestCombineErrors(t *testing.T) {