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:
Lee Sang Gyu authored and GitHub committed 2026-11-09 12:27:37 +08:00
1 parent afc0d3c676
commit 0eabb67ed4
2 files changed
+16

No files matched your search

+4
View File
@@ -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
+12
View File
@@ -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())
}