Skip to content

Commit

Permalink
refactor: replace particular request not found errors with public err…
Browse files Browse the repository at this point in the history
…or (#188)
  • Loading branch information
dirkmc authored Aug 5, 2021
1 parent 3dec10b commit 9f51ecb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ func (e RequestCancelledErr) Error() string {
return "Request Failed - Responder Cancelled"
}

// RequestNotFoundErr indicates that a request with a particular request ID was not found
type RequestNotFoundErr struct{}

func (e RequestNotFoundErr) Error() string {
return "request not found"
}

var (
// ErrExtensionAlreadyRegistered means a user extension can be registered only once
ErrExtensionAlreadyRegistered = errors.New("extension already registered")
Expand Down
6 changes: 3 additions & 3 deletions requestmanager/requestmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (crm *cancelRequestMessage) handle(rm *RequestManager) {
if !ok {
if crm.onTerminated != nil {
select {
case crm.onTerminated <- errors.New("request not found"):
case crm.onTerminated <- graphsync.RequestNotFoundErr{}:
case <-rm.ctx.Done():
}
}
Expand Down Expand Up @@ -659,7 +659,7 @@ func (rm *RequestManager) sendRequest(p peer.ID, request gsmsg.GraphSyncRequest)
func (urm *unpauseRequestMessage) unpause(rm *RequestManager) error {
inProgressRequestStatus, ok := rm.inProgressRequestStatuses[urm.id]
if !ok {
return errors.New("request not found")
return graphsync.RequestNotFoundErr{}
}
if !inProgressRequestStatus.paused {
return errors.New("request is not paused")
Expand All @@ -685,7 +685,7 @@ func (urm *unpauseRequestMessage) handle(rm *RequestManager) {
func (prm *pauseRequestMessage) pause(rm *RequestManager) error {
inProgressRequestStatus, ok := rm.inProgressRequestStatuses[prm.id]
if !ok {
return errors.New("request not found")
return graphsync.RequestNotFoundErr{}
}
if inProgressRequestStatus.paused {
return errors.New("request is already paused")
Expand Down

0 comments on commit 9f51ecb

Please sign in to comment.