fix: alerts list --limit/--offset reject invalid input instead of silently misbehaving (#578) - #589
fix: alerts list --limit/--offset reject invalid input instead of silently misbehaving (#578)#589ygd58 wants to merge 1 commit into
Conversation
…ently misbehaving (nansen-ai#578)
pr-reviewer Summary for #0cc4c18✅ No issues found The code review completed successfully with no findings. Review effort: 1/5 (Trivial) SummaryThis is a clean, focused bug fix that correctly addresses all three silent-failure modes described in the PR. The implementation is correct and consistent with the project's validation conventions. The fix is sound:
Tests are thorough: 7 new test cases cover Changeset: correctly categorized as No issues found. Ready to merge. Token usage: 3,418 input, 3,118 output, 299,469 cache read, 29,694 cache write | Usage Guide New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment |
There was a problem hiding this comment.
Auto-approved
This PR was automatically approved because:
- Claude recommends approval
- Claude assessed this as a minimal effort change
- The effort level is within the auto-approval threshold of 2
- No high or critical issues were detected
If you have any concerns, please request a manual review.
Fixes #578.
Problem
nansen alerts list --limit/--offsetsilently misbehaved instead of erroring on bad input, which is dangerous for a command whose whole audience is scripts and agents:if (options.offset)/if (options.limit)treat0as falsy, so--limit 0and--offset 0were silently ignored (treated as "not set") instead of honored.Number("abc")isNaN, andArray.prototype.slicecoerces aNaNargument to0— so--offset abcsilently became a no-op and--limit abcsilently returned zero results, with no error telling the caller their input wasn't a number.--offset(e.g.-1) was accepted and fed straight intoslice(), which treats negative indices as "from the end" — silently returning the wrong records instead of rejecting the input.Fix
--limitand--offsetare now validated as non-negative integers (checked withNumber.isInteger, not just presence), matching the strict client-side validation convention already used elsewhere in the CLI (e.g.parseSlippageBpsinbridge.js,buildPaginationinquery-options.js). Invalid input now throws aNansenErrorwithErrorCode.INVALID_PARAMSand a message naming the bad value, consistent with how this same handler already rejects--enabled --disabledtogether.0is now correctly distinguished from "unset" via!== undefinedchecks instead of truthiness.Testing
The 5 failures are pre-existing, in
src/__tests__/doctor.test.js, and reproduce identically onmainwithout this change — they rely onchmod-based unreadable-file simulation, which doesn't apply when tests run as root. Unrelated to this fix. 7 new tests added for this fix, all passing.Clean, no output.
Manual verification:
Checklist
npm testpasses (output above; unrelated pre-existing failures noted)npm run lintpassesconsole.login corepatch— bug fix, corrects previously-silent wrong behavior)src/schema.json— no changes needed (no new commands/options, just stricter validation of existing ones)