From 95336b347bf82eb1553b7a8917a5b3b1825f625a Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 27 Sep 2021 14:27:46 -0700 Subject: [PATCH] feat(graphsync): give missing blocks a named error Missing block error should have inspectable values --- graphsync.go | 12 ++++++++++++ .../asyncloader/responsecache/responsecache.go | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/graphsync.go b/graphsync.go index c46add92..07afc73c 100644 --- a/graphsync.go +++ b/graphsync.go @@ -3,6 +3,7 @@ package graphsync import ( "context" "errors" + "fmt" "github.com/ipfs/go-cid" "github.com/ipld/go-ipld-prime" @@ -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") diff --git a/requestmanager/asyncloader/responsecache/responsecache.go b/requestmanager/asyncloader/responsecache/responsecache.go index 94ecfd31..0567cf57 100644 --- a/requestmanager/asyncloader/responsecache/responsecache.go +++ b/requestmanager/asyncloader/responsecache/responsecache.go @@ -1,7 +1,6 @@ package responsecache import ( - "fmt" "sync" blocks "github.com/ipfs/go-block-format" @@ -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