Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error codes #182

Merged
merged 1 commit into from
Aug 5, 2021
Merged

Fix error codes #182

merged 1 commit into from
Aug 5, 2021

Conversation

hannahhoward
Copy link
Collaborator

Goals

Enforce returning error codes that more closely match the graphsync spec

Implementation

  • Make sure requests that are not validated return ResponseRejected
  • Make sure requests that fail to load first block return RequestFailedContentNotFound
  • Fix inconsistencies in value given to CompletedResponseListener vs returned in request
  • Add ResponseRejected to IsTerminalResponseCode (should have been there before)
  • Enforce more specific response code tests in tests of the response manager

enforce much tighter consistency with graphsync spec in usage of error codes
Comment on lines +132 to +134
if err == runtraversal.ErrFirstBlockLoad {
code = graphsync.RequestFailedContentNotFound
} else if err == errCancelledByCommand {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in some of the error cases handled here we set the code then return nil.
But in these new error cases we don't return after setting the code. Just want to confirm that's correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea so, basically the above two cases involve no final network message to send (see rb.ClearRequest)

While these cases do involve a final message back to the requestor. (see rb.FinishWithError). Ultimately they return nil two lines below that. This is a lot of nested conditionals and I agree it's confusing and merits a refactor, but yes, it's correct :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool just wanted to make sure 👍

}

// ErrFirstBlockLoad indicates the traversal was unable to load the very first block in the traversal
const ErrFirstBlockLoad = errorString("Unable to load first block")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use errors.New()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cause then it's a VAR rather than a const. I've always been anxious about golang errs being vars. cause theoretically anyone can overwrite them, so I often employ this pattern. See https://dave.cheney.net/tag/errors

@hannahhoward hannahhoward merged commit 3dec10b into release/0.6.x Aug 5, 2021
hannahhoward added a commit that referenced this pull request Aug 5, 2021
* feat: fire network error when network disconnects during request (#164)

* release: 0.6.1

* Better logging for Graphsync traversal (#167)

* log gs traversal

* Apply suggestions from code review

Co-authored-by: dirkmc <[email protected]>

* add debug logs

* add debug logs

Co-authored-by: dirkmc <[email protected]>

* release: v0.6.2 (#168)

* Fix/log blockstore reads (#169)

* log gs traversal

* Apply suggestions from code review

Co-authored-by: dirkmc <[email protected]>

* add debug logs

* fixed logging

* Apply suggestions from code review

Co-authored-by: dirkmc <[email protected]>

* fixed error

Co-authored-by: dirkmc <[email protected]>

* release: v0.6.3 (#170)

* request queued hook

* test request queued hook

* release: v0.6.4

* Resolve 175 race condition, no change to hook timing (#178)

* feat(requestmanager): add request timing (#181)

* Add cancel request and wait function (#185)

* fix(responsemanager): fix error codes (#182)

enforce much tighter consistency with graphsync spec in usage of error codes

* refactor: replace particular request not found errors with public error (#188)

* release: 0.6.8

Co-authored-by: dirkmc <[email protected]>
Co-authored-by: Aarsh Shah <[email protected]>
@mvdan mvdan deleted the fix/graphsync-errors branch December 15, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants