pagination: fix panic when the last page link has page=0 - #1889
Open
AccursedGalaxy wants to merge 1 commit into
Open
pagination: fix panic when the last page link has page=0#1889AccursedGalaxy wants to merge 1 commit into
AccursedGalaxy wants to merge 1 commit into
Conversation
lastPage() returned 0 when the links.pages.last URL had a page param that parses to 0, so PaginateResp allocated a zero-length page list and set(1, ...) panicked. A last page below 1 is never valid, so clamp it to 1 and return an empty list instead. Fixes digitalocean#1888
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.
doctl gradient agent listpanics on an account with no Gradient AI agents (#1888):The trace means
lastPage()returned 0.PaginateRespallocated a zero-length page list andset(1, ...)indexedlist[0]. The only waylastPage()returns 0 without an error is alinks.pages.lastURL whosepageparam parses to 0, which lines up with an empty collection (last = ceil(0/200) = 0). A last page below 1 is never valid whatever the server sends, solastPage()clamps it to 1 andPaginateRespreturns an empty list instead of panicking.The regression test reproduces the reported panic and passes with the fix;
go test ./do/is green.For transparency: I generated the patch with driver-os, a coding-agent harness I'm building. I wrote the regression test by hand first and confirmed it failed at base, and I reviewed the final diff myself.
Fixes #1888