Commit db1896f8 authored by hannahhoward's avatar hannahhoward

refactor(requestmanager): remove special error type

parent a27d4f91
......@@ -20,14 +20,7 @@ import (
type ResponseProgress = blocks.Block
// ResponseError is an error that occurred during a traversal.
// It can be either a "non-terminal" error -- meaning progress will
// 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
}
type ResponseError error
const (
// maxPriority is the max priority as defined by the bitswap protocol
......@@ -155,7 +148,7 @@ func (rm *RequestManager) singleErrorResponse(err error) (chan ResponseProgress,
ch := make(chan ResponseProgress)
close(ch)
errCh := make(chan ResponseError, 1)
errCh <- ResponseError{true, err}
errCh <- err
close(errCh)
return ch, errCh
}
......@@ -317,14 +310,14 @@ func (prm *processResponseMessage) handle(rm *RequestManager) {
func (rm *RequestManager) generateResponseErrorFromStatus(status gsmsg.GraphSyncResponseStatusCode) ResponseError {
switch status {
case gsmsg.RequestFailedBusy:
return ResponseError{true, fmt.Errorf("Request Failed - Peer Is Busy")}
return fmt.Errorf("Request Failed - Peer Is Busy")
case gsmsg.RequestFailedContentNotFound:
return ResponseError{true, fmt.Errorf("Request Failed - Content Not Found")}
return fmt.Errorf("Request Failed - Content Not Found")
case gsmsg.RequestFailedLegal:
return ResponseError{true, fmt.Errorf("Request Failed - For Legal Reasons")}
return fmt.Errorf("Request Failed - For Legal Reasons")
case gsmsg.RequestFailedUnknown:
return ResponseError{true, fmt.Errorf("Request Failed - Unknown Reason")}
return fmt.Errorf("Request Failed - Unknown Reason")
default:
return ResponseError{}
return fmt.Errorf("Unknown")
}
}
......@@ -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) {
select {
case err := <-errChan:
if err.Error == nil || err.IsTerminal != true {
if err == nil {
t.Fatal("should have sent a erminal error but did not")
}
case <-ctx.Done():
......
......@@ -44,7 +44,7 @@ func (rc *responseCollector) collectResponses(
}
nextError := func() ResponseError {
if len(receivedErrors) == 0 {
return ResponseError{}
return nil
}
return receivedErrors[0]
}
......
......@@ -34,8 +34,8 @@ func TestBufferingResponseProgress(t *testing.T) {
}
}
interimError := ResponseError{false, fmt.Errorf("A block was missing")}
terminalError := ResponseError{true, fmt.Errorf("Something terrible happened")}
interimError := fmt.Errorf("A block was missing")
terminalError := fmt.Errorf("Something terrible happened")
select {
case <-ctx.Done():
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