Skip to content

Commit a820662

Browse files
authored
Merge pull request #427 from SiaFoundation/chris/wrap-client-error
Wrap client errors
2 parents e0f827a + b081ba1 commit a820662

4 files changed

Lines changed: 96 additions & 53 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
# Wrap client rpc errors in RPCError.

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)