Skip to content

Commit 83ce27e

Browse files
ChrisSchinnerln8mgr
authored andcommitted
Wrap client rpc errors in RPCError
1 parent e0f827a commit 83ce27e

3 files changed

Lines changed: 91 additions & 53 deletions

File tree

rhp/v4/client_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package rhp
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
rhp4 "go.sia.tech/core/rhp/v4"
8+
)
9+
10+
func TestClientErrWrapping(t *testing.T) {
11+
sentinel := errors.New("sentinel")
12+
13+
// clientErr joins an outer ClientError with the inner error.
14+
err := clientErr("desc", sentinel)
15+
if code := rhp4.ErrorCode(err); code != rhp4.ErrorCodeClientError {
16+
t.Fatalf("expected ClientError, got %d", code)
17+
} else if !errors.Is(err, sentinel) {
18+
t.Fatal("expected inner sentinel to be in the chain")
19+
}
20+
21+
// clientErrf produces a standalone ClientError without an inner.
22+
err = clientErrf("desc %d", 1)
23+
if code := rhp4.ErrorCode(err); code != rhp4.ErrorCodeClientError {
24+
t.Fatalf("expected ClientError, got %d", code)
25+
}
26+
}

0 commit comments

Comments
 (0)