assert: reduce truncatingFormat limit so large values stay readable (#1801) - #1932
Open
oaksprout wants to merge 1 commit into
Open
assert: reduce truncatingFormat limit so large values stay readable (#1801)#1932oaksprout wants to merge 1 commit into
oaksprout wants to merge 1 commit into
Conversation
truncatingFormat's limit was sized (~32KB) purely to keep a formatted value from making the assembled failure message exceed the bufio.MaxScanTokenSize line-length limit go test's output scanner imposes, which was enough to stop failure output being dropped entirely (stretchr#1525) but still let a single assertion swamp the console with tens of kilobytes of unreadable output. As suggested by @brackendawson on stretchr#1801, reduce the limit significantly instead of special-casing Len: 4000 bytes, matching the default MaxLength used by Gomega's format package for the same purpose, while staying comfortably below bufio.MaxScanTokenSize so the original guarantee still holds. Anyone who needs the untruncated value can print it with t.Logf. This affects every assertion that shares truncatingFormat (Equal, EqualValues, EqualExportedValues, NotEqual, NotEqualValues, Nil, Empty, Len, Contains, NotContains, Subset, NotSubset, Same, NotSame, NoError, EqualError, ErrorContains, ErrorIs, NotErrorIs, ErrorAs, NotErrorAs, Zero), which is the intended scope per the issue thread. ElementsMatch is out of scope: it does not use truncatingFormat. Fixes stretchr#1801
This was referenced Jul 28, 2026
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.
You set the work. #1801: a failed
assert.Lenon a large object dumps an enormous unreadable value — and your own suggested direction was to significantly reduce the limit used byassert.truncatingFormatrather than special-casingLen.It's done.
maxMessageSizeis now a documented package const of 4000 bytes (down from ~32.7KB). The number isn't arbitrary — it matches the defaultMaxLengthin Gomega'sformatpackage, the sibling assertion library that already solved this exact problem. A regression test written before the fix pins the behaviour: aLenfailure on a 1M-element slice is ~4.3KB with the truncation marker, versus 32,755 bytes on current master.Here's the evidence.
001eb794, patch applied, modules downloaded, then the network was disconnected.go test -race ./...in a cleangolang:1.26-bookwormcontainer: all 8 packages ok, including the new regression test.go vetandgofmtclean. Nogo.mod/CI changes.truncatingFormatand now truncate at 4000 bytes — intentional per your framing ("this will prevent very very long output on all assertions... not just Len"), and the existing*TooLongToPrinttest family is limit-agnostic by construction, so it all still passes.Audit trail — an independently checkable record that these checks ran, in this order, before this PR existed
001eb7946baf451879253643e4ce4b38eaa0d4a7golang:1.26-bookworm@sha256:1ecb7edf…(linux/arm64), network off during testsWhat this proves: the checks ran, in that order, on exactly this patch, before this PR was opened — none of it can be backdated or swapped afterwards. What it doesn't prove: that the fix is right. The two signing keys are distinct but run by the same project, and the record lives on a test network. Correctness is your judgement, which is the point.
Written by an AI agent; reviewed and sent by a human who answers the review. We're testing whether work checked this way is useful to maintainers — blunt feedback welcome, including "don't".
Everything below is written by Claude
Fixes #1801.
The old limit (
bufio.MaxScanTokenSize/2 - 100) existed only to keep failure messages undergo test's 64KB line-scanner cap (the #1525 bug thattruncatingFormatoriginally fixed) — any value well below ~32KB satisfies that, so the constraint no longer needs to drive the number. The change promotes the local var to a documented package const so the reasoning travels with the code.Notes for the reviewer
Len.ElementsMatch's separate unboundedformatListDiffpath (named tangentially in the thread) is deliberately untouched — happy to file a follow-up.