mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(xerror): [xerror] drop leading ": " when message is empty (#423)
* fix(xerror): [xerror] drop leading ": " when message is empty * test(xerror): [xerror] cover Wrap without a message
This commit is contained in:
1 parent
afc0d3c676
commit
0eabb67ed4
2 files changed
+16
No files matched your search
@@ -87,6 +87,10 @@ func (e *XError) Error() string {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if msg == "" {
|
||||||
|
return cause.Error()
|
||||||
|
}
|
||||||
|
|
||||||
msg = fmt.Sprintf("%s: %v", msg, cause.Error())
|
msg = fmt.Sprintf("%s: %v", msg, cause.Error())
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|||||||
@@ -115,3 +115,15 @@ func TestXError_Info(t *testing.T) {
|
|||||||
assert.Equal(cause, errInfo.Cause)
|
assert.Equal(cause, errInfo.Cause)
|
||||||
assert.Equal("high", errInfo.Values["level"])
|
assert.Equal("high", errInfo.Values["level"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWrap_withoutMessage(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
assert := internal.NewAssert(t, "TestWrap_withoutMessage")
|
||||||
|
|
||||||
|
cause := errors.New("wrong password")
|
||||||
|
|
||||||
|
assert.Equal("wrong password", Wrap(cause).Error())
|
||||||
|
assert.Equal("wrong password", Wrap(Wrap(cause)).Error())
|
||||||
|
assert.Equal("wrong password", New("").Wrap(cause).Error())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user