-
Notifications
You must be signed in to change notification settings - Fork 25
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
Return EOF and ErrUnexpectedEOF correctly #64
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
099ab3e
Use readerWithEOFContext to handle EOF vs ErrUnexpectedEOF cases
MarcoPolo 6eb0095
fix: specialize discard for readerWithEOFContext
Stebalien 0326313
Check hasReadOnce in readByte methods
MarcoPolo eecee09
Avoid allocation in ScanForLinks
MarcoPolo 1fdee4f
fix: export eof reader and fix compile
Stebalien 3dcc3ab
feat: avoid creating new ReaderWithEOFContexts where possible
Stebalien 4343a5f
Fix GetPeeker magic
MarcoPolo 22488b2
Use defer and remove ReaderWithEOFContext
MarcoPolo 083da62
feat: simplify "read once" checks
Stebalien 86717ea
fix: check for unexpected EOF in deferred unmarshaling
Stebalien e120cdc
Add TestErrUnexpectedEOF
MarcoPolo ae38a94
Use errors.Is to detect wrapped EOF errors
MarcoPolo b23fed4
Wrap error at end so we don't lose error context
MarcoPolo 19357f6
Remove expectation of ErrUnexpectedEOF we just want to make sure we d…
MarcoPolo 0396fd1
Revert "Wrap error at end so we don't lose error context"
MarcoPolo c353e0a
Revert "Use errors.Is to detect wrapped EOF errors"
MarcoPolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite work.
%w
needs to be last.It's probably fine to just leave it as-is? The only thing we really care about is not returning an EOF if we've read bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it? https://go.dev/play/p/k2wOyoCk4WO makes it seem like both work.
I figured we cared enough to wrap the original error, so might be nice to keep that info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, being last only matters for
Unwrap
. (docs: https://pkg.go.dev/golang.org/x/xerrors#Errorf)My point was: that we could just leave everything as-is. I.e., we don't want an EOF unless we read no data, but we're fine with any other error (including a wrapped EOF) otherwise.
But if this works and doesn't hurt performance too much, then it's fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From that link
What is the "error's Format method" ?
anyways, I understand what you mean by as-is. I changed this to return the wrapped error and only replace if we return EOF. I also changed the test to only check that we aren't returning EOF exactly if it could read some bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ I'm having a lot of difficulty with those docs.