Skip to content

fix: cap API per_page, guard null alert names, fix log hasMore logic#1158

Draft
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sentry-cli-bug-fixes-e20f
Draft

fix: cap API per_page, guard null alert names, fix log hasMore logic#1158
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/sentry-cli-bug-fixes-e20f

Conversation

@cursor

@cursor cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Three independent defensive bug fixes discovered through codebase audit:

1. log list per_page exceeds API max and hasMore is wrong

Root cause: listLogs() and listTraceLogs() sent the raw --limit value (up to 1000) as per_page to the Sentry API, which silently caps at 100. The hasMore logic compared logs.length >= flags.limit (e.g., 100 >= 200 = false), hiding available data.

Reproduction: sentry log list --limit 200 returns 100 items but says no more are available.

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.

Files: src/lib/api/logs.ts, src/commands/log/list.ts


2. Alert rule name null crash in --query filter and name resolution

Root cause: Alert list commands and rule-resolve helpers call rule.name.toLowerCase() without null guards. The API response is cast via as MetricAlertRule without Zod validation, so null/undefined names crash with TypeError. Same class of bug as dashboard #1097 (fixed with title ?? "(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.ts


3. handleOrgAll and project list send uncapped perPage to API

Root cause: handleOrgAll() in org-list.ts passed flags.limit (up to 1000) directly as perPage. The Sentry API silently caps per_page at 100, so --limit 200 returns at most 100 items.

Reproduction: sentry team list my-org/ --limit 200 returns at most 100 teams.

Fix: Cap perPage at Math.min(flags.limit, API_MAX_PER_PAGE) in both handleOrgAll() and the project list org-all handler.

Files: src/lib/org-list.ts, src/commands/project/list.ts

Open in Web View Automation 

cursoragent and others added 3 commits June 29, 2026 12:16
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>
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1158/

Built to branch gh-pages at 2026-06-29 12:18 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5132 uncovered lines.
✅ Project coverage is 81.48%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/commands/alert/issues/rule-resolve.ts 100.00% ⚠️ 1 partials
src/commands/alert/metrics/rule-resolve.ts 100.00% ⚠️ 1 partials
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

@betegon

betegon commented Jun 29, 2026

Copy link
Copy Markdown
Member

i <3 u @cursoragent

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.

2 participants