Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-graphsync
Commits
db1896f8
Commit
db1896f8
authored
Mar 20, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(requestmanager): remove special error type
parent
a27d4f91
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
18 deletions
+11
-18
requestmanager/requestmanager.go
requestmanager/requestmanager.go
+7
-14
requestmanager/requestmanager_test.go
requestmanager/requestmanager_test.go
+1
-1
requestmanager/responsecollector.go
requestmanager/responsecollector.go
+1
-1
requestmanager/responsecollector_test.go
requestmanager/responsecollector_test.go
+2
-2
No files found.
requestmanager/requestmanager.go
View file @
db1896f8
...
@@ -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"
)
}
}
}
}
requestmanager/requestmanager_test.go
View file @
db1896f8
...
@@ -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
()
:
...
...
requestmanager/responsecollector.go
View file @
db1896f8
...
@@ -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
]
}
}
...
...
requestmanager/responsecollector_test.go
View file @
db1896f8
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment