Skip to content

Round down a fractional challenge list limit instead of crashing - #117

Open
owizdom wants to merge 1 commit into
Lucid-Computing:mainfrom
owizdom:owizdom/api-fractional-limit
Open

owizdom wants to merge 1 commit into
Lucid-Computing:mainfrom
owizdom:owizdom/api-fractional-limit

Conversation

@owizdom

@owizdom owizdom commented Nov 27, 2026 •

Copy link
Copy Markdown

Change

GET /api/v1/challenges?limit=2.5 returns 500 on https://akashi.lucidcomputing.ai (Cloudflare error code: 1101, an uncaught Worker exception), while ?limit=2 returns 200. The route clamps limit to 1..100 but keeps the fraction, and D1 refuses a fractional LIMIT with D1_ERROR: datatype mismatch, which nothing catches. Any limit strictly between 1 and 100 with a fraction did the same.

The limit is now rounded down after the clamp, so 2.5 lists 2 challenges. Every value that worked before gives the same result, including 0.5 (1), 100.5 (100), 1e3 (100) and abc (20).

Rounding down follows how this parameter already treats other values: it clamps or defaults them rather than refusing them. If you would rather answer 400 for a non-integer limit, I can change it. No CHANGELOG line, since earlier api/ changes have not added one.

Verification

npm ci then npm run check in api/ on Node 24.22.3, as in api.yml, from a fresh clone of this branch: types pass and 11 tests pass. With src/index.ts from main, the new test fails with the D1 error. Under wrangler dev, ?limit=2.5 and ?limit=1.5 answered 500 on eccb15e and 200 here.

GET /api/v1/challenges?limit=2.5 passed 2.5 to D1 as the LIMIT, which
SQLite refuses with "datatype mismatch", and the Worker threw. The
limit is now rounded down after the existing clamp, so every value
that worked before gives the same result.
@owizdom
owizdom marked this pull request as ready for review November 27, 2026 14:12

This branch has not been deployed

No deployments
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.

1 participant