assert: fix failure message hidden when a diff line exceeds 64KiB#1925
Open
malikov73 wants to merge 1 commit into
Open
assert: fix failure message hidden when a diff line exceeds 64KiB#1925malikov73 wants to merge 1 commit into
malikov73 wants to merge 1 commit into
Conversation
stretchr#746) indentMessageLines used bufio.Scanner, which errors out on lines longer than bufio.MaxScanTokenSize (64KiB) and replaced the whole failure message with "cannot display message: bufio.Scanner: token too long". This happened e.g. on assert.Equal of long single-line strings or of structs with a long string field, because diff() output is not truncated. Split the message manually instead, preserving bufio.ScanLines semantics (trailing final newline ignored, \r\n treated as a line ending).
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.
Summary
Bug fix. Fixes #746.
indentMessageLinesusesbufio.Scanner, which errors out on lines longer thanbufio.MaxScanTokenSize(64KiB). When that happens, the entire labeled content is replaced withcannot display message: bufio.Scanner: token too long, so the user sees neither the diff nor the values — only an emptyError:section.truncatingFormatprotects theexpected:/actual:representations, butdiff()output is not truncated, so this still reproduces today, e.g.:prints
The same happens for structs with a long string field (
spewprints strings on one line) and for a long single-line user message inmsgAndArgs.Changes
indentMessageLinessplits the message withstrings.Splitinstead ofbufio.Scanner, so there is no line-length limit and thecannot display messagefailure mode is gone.bufio.ScanLinessemantics are preserved: the empty element after a trailing final"\n"is ignored and"\r\n"is treated as a line ending (a trailing"\r"is stripped from each line).TestEqualLongDiffLines(fails on master withcannot display message: bufio.Scanner: token too long, passes with the fix).No API changes; output is byte-for-byte identical for messages that the scanner could already handle.