testify icon indicating copy to clipboard operation
testify copied to clipboard

assert: handle TokenTooLong error scenario

Open arjunmahishi opened this issue 11 months ago • 3 comments

Summary

As pointed out in #1525, when the assertion message is too long, it gets completely truncated in the final output. This is because bufio.Scanner.Scan() has a default MaxScanTokenSize set to 65536 characters (64 * 1024). The Scan() function returns false whenever the line being scanned exceeds that max limit. This leads to the final assertion message being truncated.

Changes

This commit fixes that by manually setting the internal scan buffer size to len(message) + 1 to make sure that the above scenario never occurs.

Related issues

Fixes #1525

arjunmahishi avatar Mar 03 '24 11:03 arjunmahishi

@dolmen @brackendawson Can you please take one last look at this? I think it's ready to be merged

arjunmahishi avatar Mar 07 '24 05:03 arjunmahishi

@dolmen Are we good to merge?

arjunmahishi avatar Mar 08 '24 15:03 arjunmahishi

I'm not yet convinced that the tests provide enough coverage. I would like to see more clearly a check related to bufio boundaries.

I feel that we are testing with strings much longer than the boundary, and not just below and at the boundary. I have to dig into the code more carefully.

dolmen avatar Mar 10 '24 10:03 dolmen