fix: cap API per_page, guard null alert names, fix log hasMore logic#1158
Draft
cursor[bot] wants to merge 3 commits into
Draft
fix: cap API per_page, guard null alert names, fix log hasMore logic#1158cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
The listLogs() and listTraceLogs() API functions sent the raw --limit value (up to 1000) as per_page to the Sentry API, which silently caps at 100. This caused: 1. Requesting --limit 200 would only return 100 items 2. hasMore was computed as logs.length >= flags.limit (100 >= 200 = false), hiding the fact that more data exists from the user Fix: Cap per_page at Math.min(limit, API_MAX_PER_PAGE) in both API functions, and compute hasMore against the effective per-page value so users see the 'more available' hint correctly. Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
The alert list commands and rule-resolve helpers accessed rule.name without null guards. When the Sentry API returns alert rules with null or undefined names (e.g. draft rules, data migration artifacts), this crashes with TypeError on .toLowerCase(). Same class of bug as dashboard #1097 which was fixed with title ?? '(untitled)'. Fix: Add ?? '' guards on .toLowerCase() calls in --query filtering, ?? '(untitled)' guards in table rendering, and truthiness checks in name resolution and fuzzy matching. Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
handleOrgAll() in org-list.ts and the project list org-all handler passed flags.limit (up to 1000) directly as perPage to the API. The Sentry API silently caps per_page at 100, causing: 1. --limit 200 returns at most 100 items per page 2. Users think they've seen everything when more data exists This affected all commands using buildOrgListCommand (team list, repo list, release list) and the project list org-all mode. Fix: Cap perPage at Math.min(flags.limit, API_MAX_PER_PAGE). Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
Contributor
|
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 5132 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 81.48% 81.48% —%
==========================================
Files 397 397 —
Lines 27702 27706 +4
Branches 17991 18007 +16
==========================================
+ Hits 22570 22574 +4
- Misses 5132 5132 —
- Partials 1862 1862 —Generated by Codecov Action |
Member
|
i <3 u @cursoragent |
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.
Summary
Three independent defensive bug fixes discovered through codebase audit:
1.
log listper_page exceeds API max andhasMoreis wrongRoot cause:
listLogs()andlistTraceLogs()sent the raw--limitvalue (up to 1000) asper_pageto the Sentry API, which silently caps at 100. ThehasMorelogic comparedlogs.length >= flags.limit(e.g.,100 >= 200 = false), hiding available data.Reproduction:
sentry log list --limit 200returns 100 items but says no more are available.Fix: Cap
per_pageatMath.min(limit, API_MAX_PER_PAGE)in both API functions, and computehasMoreagainst the effective per-page value.Files:
src/lib/api/logs.ts,src/commands/log/list.ts2. Alert rule name null crash in
--queryfilter and name resolutionRoot cause: Alert list commands and rule-resolve helpers call
rule.name.toLowerCase()without null guards. The API response is cast viaas MetricAlertRulewithout Zod validation, so null/undefined names crash withTypeError. Same class of bug as dashboard #1097 (fixed withtitle ?? "(untitled)").Reproduction:
sentry alert metrics list --query "test"when any alert rule in the org has a null/undefined name.Fix: Add
?? ""guards on.toLowerCase()filtering,?? "(untitled)"guards in table rendering, and truthiness checks in name resolution/fuzzy matching.Files:
src/commands/alert/metrics/list.ts,src/commands/alert/issues/list.ts,src/commands/alert/metrics/rule-resolve.ts,src/commands/alert/issues/rule-resolve.ts3.
handleOrgAlland project list send uncappedperPageto APIRoot cause:
handleOrgAll()inorg-list.tspassedflags.limit(up to 1000) directly asperPage. The Sentry API silently capsper_pageat 100, so--limit 200returns at most 100 items.Reproduction:
sentry team list my-org/ --limit 200returns at most 100 teams.Fix: Cap
perPageatMath.min(flags.limit, API_MAX_PER_PAGE)in bothhandleOrgAll()and the project list org-all handler.Files:
src/lib/org-list.ts,src/commands/project/list.ts