diff --git a/path/error.go b/path/error.go index 34f599380..0863c7cf4 100644 --- a/path/error.go +++ b/path/error.go @@ -16,17 +16,17 @@ type ErrInvalidPath struct { path string } -func (e ErrInvalidPath) Error() string { +func (e *ErrInvalidPath) Error() string { return fmt.Sprintf("invalid path %q: %s", e.path, e.err) } -func (e ErrInvalidPath) Unwrap() error { +func (e *ErrInvalidPath) Unwrap() error { return e.err } -func (e ErrInvalidPath) Is(err error) bool { +func (e *ErrInvalidPath) Is(err error) bool { switch err.(type) { - case ErrInvalidPath, *ErrInvalidPath: + case *ErrInvalidPath: return true default: return false diff --git a/path/error_test.go b/path/error_test.go index 512195e04..2b5f92945 100644 --- a/path/error_test.go +++ b/path/error_test.go @@ -6,11 +6,7 @@ import ( ) func TestErrorIs(t *testing.T) { - if !errors.Is(ErrInvalidPath{path: "foo", err: errors.New("bar")}, ErrInvalidPath{}) { - t.Fatal("error must be error") - } - - if !errors.Is(&ErrInvalidPath{path: "foo", err: errors.New("bar")}, ErrInvalidPath{}) { + if !errors.Is(&ErrInvalidPath{path: "foo", err: errors.New("bar")}, &ErrInvalidPath{}) { t.Fatal("pointer to error must be error") } } diff --git a/path/path.go b/path/path.go index 75eb4d3d0..4230e298a 100644 --- a/path/path.go +++ b/path/path.go @@ -111,7 +111,7 @@ type immutablePath struct { func NewImmutablePath(p Path) (ImmutablePath, error) { if p.Namespace().Mutable() { - return nil, ErrInvalidPath{err: ErrExpectedImmutable, path: p.String()} + return nil, &ErrInvalidPath{err: ErrExpectedImmutable, path: p.String()} } segments := p.Segments() diff --git a/path/path_test.go b/path/path_test.go index 1a77fcf80..08b692f39 100644 --- a/path/path_test.go +++ b/path/path_test.go @@ -86,7 +86,7 @@ func TestNewPath(t *testing.T) { {"/ipfs/", ErrInsufficientComponents}, {"ipfs/", ErrInsufficientComponents}, {"ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n", ErrInsufficientComponents}, - {"/ipld/foo", ErrInvalidPath{}}, + {"/ipld/foo", &ErrInvalidPath{}}, {"/ipld/", ErrInsufficientComponents}, {"ipld/", ErrInsufficientComponents}, {"ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n", ErrInsufficientComponents}, @@ -102,7 +102,7 @@ func TestNewPath(t *testing.T) { for _, testCase := range testCases { _, err := NewPath(testCase.src) assert.ErrorIs(t, err, testCase.err) - assert.ErrorIs(t, err, ErrInvalidPath{}) // Always an ErrInvalidPath! + assert.ErrorIs(t, err, &ErrInvalidPath{}) // Always an ErrInvalidPath! } }) @@ -218,7 +218,7 @@ func TestNewImmutablePath(t *testing.T) { _, err = NewImmutablePath(p) assert.ErrorIs(t, err, ErrExpectedImmutable) - assert.ErrorIs(t, err, ErrInvalidPath{}) + assert.ErrorIs(t, err, &ErrInvalidPath{}) } })