mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
improve package gerror
This commit is contained in:
@ -44,16 +44,14 @@ func (err *Error) Error() string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
if err.text != "" {
|
||||
if err.error != nil {
|
||||
return err.text + ": " + err.error.Error()
|
||||
}
|
||||
return err.text
|
||||
}
|
||||
errStr := err.text
|
||||
if err.error != nil {
|
||||
err.error.Error()
|
||||
if err.text != "" {
|
||||
errStr += ": "
|
||||
}
|
||||
errStr += err.error.Error()
|
||||
}
|
||||
return ""
|
||||
return errStr
|
||||
}
|
||||
|
||||
// Code returns the error code.
|
||||
|
||||
@ -34,7 +34,6 @@ func Test_Wrap(t *testing.T) {
|
||||
t.AssertNE(err, nil)
|
||||
t.Assert(err.Error(), "3: 2: 1")
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gerror.New("1")
|
||||
err = gerror.Wrap(err, "2")
|
||||
@ -42,6 +41,12 @@ func Test_Wrap(t *testing.T) {
|
||||
t.AssertNE(err, nil)
|
||||
t.Assert(err.Error(), "3: 2: 1")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gerror.New("1")
|
||||
err = gerror.Wrap(err, "")
|
||||
t.AssertNE(err, nil)
|
||||
t.Assert(err.Error(), "1")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Cause(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user