Skip to content

Commit

Permalink
feat(graphsync): give missing blocks a named error (#227)
Browse files Browse the repository at this point in the history
Missing block error should have inspectable values
  • Loading branch information
hannahhoward authored Sep 29, 2021
1 parent c691887 commit 3408ceb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 12 additions & 0 deletions graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package graphsync
import (
"context"
"errors"
"fmt"

"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
Expand Down Expand Up @@ -94,6 +95,17 @@ func (e RequestNotFoundErr) Error() string {
return "request not found"
}

// RemoteMissingBlockErr indicates that the remote peer was missing a block
// in the selector requested. It is a non-terminal error in the error stream
// for a request and does NOT cause a request to fail completely
type RemoteMissingBlockErr struct {
Link ipld.Link
}

func (e RemoteMissingBlockErr) Error() string {
return fmt.Sprintf("remote peer is missing block: %s", e.Link.String())
}

var (
// ErrExtensionAlreadyRegistered means a user extension can be registered only once
ErrExtensionAlreadyRegistered = errors.New("extension already registered")
Expand Down
3 changes: 1 addition & 2 deletions requestmanager/asyncloader/responsecache/responsecache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package responsecache

import (
"fmt"
"sync"

blocks "github.com/ipfs/go-block-format"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (rc *ResponseCache) AttemptLoad(requestID graphsync.RequestID, link ipld.Li
rc.responseCacheLk.Lock()
defer rc.responseCacheLk.Unlock()
if rc.linkTracker.IsKnownMissingLink(requestID, link) {
return nil, fmt.Errorf("remote peer is missing block: %s", link.String())
return nil, graphsync.RemoteMissingBlockErr{Link: link}
}
data, _ := rc.unverifiedBlockStore.VerifyBlock(link, linkContext)
return data, nil
Expand Down

0 comments on commit 3408ceb

Please sign in to comment.