json: return writer errors from Encoder.Encode#163
Open
c-tonneslan wants to merge 1 commit into
Open
Conversation
The inner `if _, err := enc.writer.Write(b)` shadowed the outer err with :=, so the writer error got stored on enc.err but the function still returned the (nil) outer err. First Encode after a write failure would look like it succeeded; only the next call would surface the error via the enc.err early-return at the top. Switch the assignment to = so the outer err is set, then returned. Closes segmentio#139 Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The inner
if _, err := enc.writer.Write(b)shadowed the outererrwith:=, so the writer error got cached onenc.errbut the function still returned the (nil) outererr. The firstEncodeafter a write failure looked like a success; only the next call would surface the cached error via the early return at the top.Switching to
=so the outererractually receives the writer error.Test fails on master, passes here. Closes #139.