Commit db1896f8 authored by hannahhoward's avatar hannahhoward

refactor(requestmanager): remove special error type

parent a27d4f91
...@@ -20,14 +20,7 @@ import ( ...@@ -20,14 +20,7 @@ import (
type ResponseProgress = blocks.Block type ResponseProgress = blocks.Block
// ResponseError is an error that occurred during a traversal. // ResponseError is an error that occurred during a traversal.
// It can be either a "non-terminal" error -- meaning progress will type ResponseError error
// continue to happen in the future.
// or it can be a terminal error, meaning no further progress or errors
// will emit.
type ResponseError struct {
IsTerminal bool
Error error
}
const ( const (
// maxPriority is the max priority as defined by the bitswap protocol // maxPriority is the max priority as defined by the bitswap protocol
...@@ -155,7 +148,7 @@ func (rm *RequestManager) singleErrorResponse(err error) (chan ResponseProgress, ...@@ -155,7 +148,7 @@ func (rm *RequestManager) singleErrorResponse(err error) (chan ResponseProgress,
ch := make(chan ResponseProgress) ch := make(chan ResponseProgress)
close(ch) close(ch)
errCh := make(chan ResponseError, 1) errCh := make(chan ResponseError, 1)
errCh <- ResponseError{true, err} errCh <- err
close(errCh) close(errCh)
return ch, errCh return ch, errCh
} }
...@@ -317,14 +310,14 @@ func (prm *processResponseMessage) handle(rm *RequestManager) { ...@@ -317,14 +310,14 @@ func (prm *processResponseMessage) handle(rm *RequestManager) {
func (rm *RequestManager) generateResponseErrorFromStatus(status gsmsg.GraphSyncResponseStatusCode) ResponseError { func (rm *RequestManager) generateResponseErrorFromStatus(status gsmsg.GraphSyncResponseStatusCode) ResponseError {
switch status { switch status {
case gsmsg.RequestFailedBusy: case gsmsg.RequestFailedBusy:
return ResponseError{true, fmt.Errorf("Request Failed - Peer Is Busy")} return fmt.Errorf("Request Failed - Peer Is Busy")
case gsmsg.RequestFailedContentNotFound: case gsmsg.RequestFailedContentNotFound:
return ResponseError{true, fmt.Errorf("Request Failed - Content Not Found")} return fmt.Errorf("Request Failed - Content Not Found")
case gsmsg.RequestFailedLegal: case gsmsg.RequestFailedLegal:
return ResponseError{true, fmt.Errorf("Request Failed - For Legal Reasons")} return fmt.Errorf("Request Failed - For Legal Reasons")
case gsmsg.RequestFailedUnknown: case gsmsg.RequestFailedUnknown:
return ResponseError{true, fmt.Errorf("Request Failed - Unknown Reason")} return fmt.Errorf("Request Failed - Unknown Reason")
default: default:
return ResponseError{} return fmt.Errorf("Unknown")
} }
} }
...@@ -79,7 +79,7 @@ func readNBlocks(ctx context.Context, t *testing.T, blocksChan <-chan ResponsePr ...@@ -79,7 +79,7 @@ func readNBlocks(ctx context.Context, t *testing.T, blocksChan <-chan ResponsePr
func verifySingleTerminalError(ctx context.Context, t *testing.T, errChan <-chan ResponseError) { func verifySingleTerminalError(ctx context.Context, t *testing.T, errChan <-chan ResponseError) {
select { select {
case err := <-errChan: case err := <-errChan:
if err.Error == nil || err.IsTerminal != true { if err == nil {
t.Fatal("should have sent a erminal error but did not") t.Fatal("should have sent a erminal error but did not")
} }
case <-ctx.Done(): case <-ctx.Done():
......
...@@ -44,7 +44,7 @@ func (rc *responseCollector) collectResponses( ...@@ -44,7 +44,7 @@ func (rc *responseCollector) collectResponses(
} }
nextError := func() ResponseError { nextError := func() ResponseError {
if len(receivedErrors) == 0 { if len(receivedErrors) == 0 {
return ResponseError{} return nil
} }
return receivedErrors[0] return receivedErrors[0]
} }
......
...@@ -34,8 +34,8 @@ func TestBufferingResponseProgress(t *testing.T) { ...@@ -34,8 +34,8 @@ func TestBufferingResponseProgress(t *testing.T) {
} }
} }
interimError := ResponseError{false, fmt.Errorf("A block was missing")} interimError := fmt.Errorf("A block was missing")
terminalError := ResponseError{true, fmt.Errorf("Something terrible happened")} terminalError := fmt.Errorf("Something terrible happened")
select { select {
case <-ctx.Done(): case <-ctx.Done():
t.Fatal("should have written error to channel but didn't") t.Fatal("should have written error to channel but didn't")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment