Fix: Pagy::OverflowError (MAYBE-MARKETING-3D) #255
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.
The error
Pagy::OverflowError: expected :page in 1..362; got 363
occurs when a user tries to access a page number that exceeds the total number of available pages. This is a common scenario in pagination, especially when:The original code had the overflow handling commented out, causing Pagy to raise an exception when encountering these situations. This creates a poor user experience and generates unnecessary error logs.
To fix this, we're making two critical changes to the Pagy configuration:
require 'pagy/extras/overflow'
- this loads the necessary code to handle overflow situations gracefullyPagy::DEFAULT[:overflow] = :empty_page
- this configures Pagy to return an empty result set when accessing a page beyond the available range, rather than throwing an errorThe
:empty_page
strategy is chosen because it's the most user-friendly approach:This change maintains the original functionality while making it more robust and user-friendly.
Error Details
Summary:
Stacktrace:
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn’t look right, click to retry this interaction.
Quick links: View in Sentry • View in Revise