fix: fail when acting on the browser after an expected exception - #207
Merged
kbond merged 4 commits intoAug 29, 2026
Merged
Conversation
After expectException() and a request that throws, the throwing request never produced a response, so the client still holds the state of an earlier request (or none at all). Actions and assertions then either leak a raw BadMethodCallException from BrowserKit or silently run against the previous page. wrapRequest() now records that the expected exception was consumed and ensureNoException() fails the next action with an explicit message until another request is made. Fixes zenstruck#202
… and crawler() These read the response without going through `page()`, so they skipped the check entirely and asserted against the previous request's page. `ensureNoException()` is split so they get the stale-response check without the exception-page detection: asserting the status of an error page is legitimate.
They navigate without going through `wrapRequest()`, so the flag survived and left the browser failing on a page that is perfectly valid. Only reachable through the Mink driver today.
`content()` went through `page()`, so it was the only route to an error page's body that failed: `crawler()->html()`, `client()->getResponse()`, `saveSource()` and `dump()` all already allowed it.
kbond
force-pushed
the
fix-202-stale-state-after-expected-exception
branch
from
August 29, 2026 14:46
97a4b3d to
fa9c6ec
Compare
kbond
approved these changes
Aug 29, 2026
kbond
left a comment
Member
There was a problem hiding this comment.
Thanks! I pushed a few commits on top: assertStatus(), assertSuccessful() and crawler() were skipping the check entirely, back()/forward()/reload() never cleared the flag, and I loosened content() so an error page body can still be read.
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.
Fixes #202
Implements the proposal from the issue, in the shared layer so both browsers get the same behavior:
Driver::wrapRequest()records that the expected exception was consumed (the flag is cleared by the next request and byreset()).Session::ensureNoException()already runs before every action and assertion, so it now fails fast with "The last request threw the expected exception: make another request before continuing." instead of leaking BrowserKit'sBadMethodCallExceptionor silently acting on the previous page.The shared test covers the three cases from the issue: stale previous page, no previous request at all, and recovery once another request is made.
Thanks for writing the issue up with the proposal included, it basically reviewed itself. 😄