refactor: simply errors (#15067)

This commit is contained in:
Julien Robert
2023-02-20 12:03:40 +00:00
committed by GitHub
parent f69b9ff58f
commit 067ee92d4d
51 changed files with 391 additions and 160 deletions
+3 -23
View File
@@ -67,12 +67,12 @@ func (s *errorsTestSuite) TestErrorIs() {
},
"successful comparison to a wrapped error": {
a: ErrUnauthorized,
b: errorsmod.Wrap(ErrUnauthorized, "gone"),
b: Wrap(ErrUnauthorized, "gone"),
wantIs: true,
},
"unsuccessful comparison to a wrapped error": {
a: ErrUnauthorized,
b: errorsmod.Wrap(ErrInsufficientFee, "too big"),
b: Wrap(ErrInsufficientFee, "too big"),
wantIs: false,
},
"not equal to stdlib error": {
@@ -82,7 +82,7 @@ func (s *errorsTestSuite) TestErrorIs() {
},
"not equal to a wrapped stdlib error": {
a: ErrUnauthorized,
b: errorsmod.Wrap(fmt.Errorf("stdlib error"), "wrapped"),
b: Wrap(fmt.Errorf("stdlib error"), "wrapped"),
wantIs: false,
},
"nil is nil": {
@@ -224,26 +224,6 @@ func (s *errorsTestSuite) TestGRPCStatus() {
s.Require().Equal("codespace testtesttest code 38: not found: test", status.Message())
}
func ExampleWrap() {
err1 := Wrap(ErrInsufficientFunds, "90 is smaller than 100")
err2 := errorsmod.Wrap(ErrInsufficientFunds, "90 is smaller than 100")
fmt.Println(err1.Error())
fmt.Println(err2.Error())
// Output:
// 90 is smaller than 100: insufficient funds
// 90 is smaller than 100: insufficient funds
}
func ExampleWrapf() {
err1 := Wrap(ErrInsufficientFunds, "90 is smaller than 100")
err2 := errorsmod.Wrap(ErrInsufficientFunds, "90 is smaller than 100")
fmt.Println(err1.Error())
fmt.Println(err2.Error())
// Output:
// 90 is smaller than 100: insufficient funds
// 90 is smaller than 100: insufficient funds
}
const testCodespace = "testtesttest"
var (