Skip to content

Add partial body to failing uses of bodyContains for debugging#1900

Merged
MaxGabriel merged 2 commits intomasterfrom
bodyContainsDebuggingMessage
Jan 26, 2026
Merged

Add partial body to failing uses of bodyContains for debugging#1900
MaxGabriel merged 2 commits intomasterfrom
bodyContainsDebuggingMessage

Conversation

@MaxGabriel
Copy link
Member

@MaxGabriel MaxGabriel commented Jan 26, 2026

When statusIs fails and the content is UTF-8 (i.e. like, not a giant JPEG or something), we print a partial body to aid in debugging. For small bodies this is sometimes sufficient to print the whole thing, and especially is helpful to indicate a general direction if the body is way off (e.g. the body for a 500 vs a 200).

This PR applies that same helpful error message to failing bodyContains and bodyNotContains calls.

A potential variant would be to print the full body, which bodyEquals does. That could be more helpful, but there is also some risk that bodyContains and bodyNotContains are being used because it is an enormous response body, and printing the full thing would dump a lot of content.

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

@MaxGabriel MaxGabriel marked this pull request as ready for review January 26, 2026 16:30
@MaxGabriel
Copy link
Member Author

Tested this locally just by modifying a test in yesod-test's own suite. Example error messages:

Expected body to contain `colorCheckBoxes = [Red,Gray]`. For debugging, the body was: CheckboxesForm {colorCheckBoxes = [Red]}
Expected body to contain `colorCheckBoxes = [Blue]`. For debugging, the body was: CheckboxesForm {colorCheckBoxes = [Red,Gray]}

Copy link
Contributor

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hell yeah

@MaxGabriel MaxGabriel merged commit 337c36c into master Jan 26, 2026
13 checks passed
@MaxGabriel
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants