improve package gerror

This commit is contained in:
John Guo
2020-12-11 00:45:15 +08:00
parent 688e327f15
commit 1d1e64b834
2 changed files with 12 additions and 9 deletions

View File

@ -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.

View File

@ -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) {