Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Define ErrNotPinned alongside the Pinner interface
Browse files Browse the repository at this point in the history
Allows for alternative implementation with the same error being part of the interface contract.
  • Loading branch information
MichaelMure authored and aschmahmann committed Jul 9, 2021
1 parent 038bb36 commit 3565d71
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 1 addition & 4 deletions dspinner/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ const (
)

var (
// ErrNotPinned is returned when trying to unpin items that are not pinned.
ErrNotPinned = errors.New("not pinned or pinned indirectly")

log logging.StandardLogger = logging.Logger("pin")

linkDirect, linkRecursive string
Expand Down Expand Up @@ -346,7 +343,7 @@ func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error {
return err
}
if !has {
return ErrNotPinned
return ipfspinner.ErrNotPinned
}
}

Expand Down
4 changes: 2 additions & 2 deletions dspinner/pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func TestPinnerBasic(t *testing.T) {
}

err = p.Unpin(ctx, dk, true)
if err != ErrNotPinned {
t.Fatal("expected error:", ErrNotPinned)
if err != ipfspin.ErrNotPinned {
t.Fatal("expected error:", ipfspin.ErrNotPinned)
}

err = p.Flush(ctx)
Expand Down
4 changes: 4 additions & 0 deletions pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func StringToMode(s string) (Mode, bool) {
return mode, ok
}

// ErrNotPinned is returned when trying to unpin items that are not pinned.
var ErrNotPinned = fmt.Errorf("not pinned or pinned indirectly")

// A Pinner provides the necessary methods to keep track of Nodes which are
// to be kept locally, according to a pin mode. In practice, a Pinner is in
// in charge of keeping the list of items from the local storage that should
Expand All @@ -93,6 +96,7 @@ type Pinner interface {

// Unpin the given cid. If recursive is true, removes either a recursive or
// a direct pin. If recursive is false, only removes a direct pin.
// If the pin doesn't exist, return ErrNotPinned
Unpin(ctx context.Context, cid cid.Cid, recursive bool) error

// Update updates a recursive pin from one cid to another
Expand Down

0 comments on commit 3565d71

Please sign in to comment.