Skip to content

fix(event view): recognize numeric issue IDs and bare "latest"#1297

Open
sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix/event-view-id-parsing
Open

fix(event view): recognize numeric issue IDs and bare "latest"#1297
sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix/event-view-id-parsing

Conversation

@sentry

@sentry sentry Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

This PR addresses CLI-1F5, where sentry event view would fail with a ValidationError: Invalid event ID "17370". Expected a 32-character hexadecimal string. when users provided a numeric Sentry issue ID (e.g., "17370") or the bare string "latest" as the event identifier.

The root cause was that the parseSingleArg and parsePositionalArgs functions in src/commands/event/view.ts did not explicitly handle these common user inputs. They were passed directly to validateHexId, which correctly rejected them as not being 32-character hexadecimal strings.

This fix introduces checks in both parseSingleArg and the two-argument path of parsePositionalArgs:

  1. Numeric Issue IDs: If the event ID argument is an all-digit string (e.g., "17370"), it is now treated as an issueId and mapped to LATEST_EVENT_SENTINEL. This routes the request to the existing getLatestEvent logic, which fetches the latest event for that issue.
  2. Bare "latest": If the event ID argument is the string "latest" (case-insensitive), it is now mapped to LATEST_EVENT_SENTINEL. This leverages the existing logic for fetching the latest event for a project.

Additionally, a top-level regex constant ALL_DIGITS_RE was introduced to satisfy Biome's lint/performance/useTopLevelRegex rule, which was triggered by the inline regexes used in the initial implementation.

Fixes CLI-1F5

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@github-actions

github-actions Bot commented Jul 25, 2026

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-1297/

Built to branch gh-pages at 2026-07-25 11:48 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

❌ Patch coverage is 45.45%. Project has 5500 uncovered lines.
❌ Project coverage is 81.74%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/commands/event/view.ts 45.45% ⚠️ 6 Missing and 4 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.75%    81.74%    -0.01%
==========================================
  Files          428       428         —
  Lines        30106     30117       +11
  Branches     19593     19605       +12
==========================================
+ Hits         24611     24617        +6
- Misses        5495      5500        +5
- Partials      2054      2060        +6

Generated by Codecov Action

Comment on lines +260 to +262
if (eventId.toLowerCase() === "latest") {
return { eventId: LATEST_EVENT_SENTINEL, targetArg };
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bare 'latest' sentinel without issueId falls through to broken event resolution

Returning LATEST_EVENT_SENTINEL for bare latest without setting issueId causes downstream event resolution to fail — getEvent and resolveEventInOrg do not support event_id: 'latest' without an issue_id.

Evidence
  • parseSingleArg returns { eventId: LATEST_EVENT_SENTINEL, targetArg } when eventId is 'latest', but never sets issueId or issueShortId.
  • resolveIssueShortcut only handles shortcuts when issueId or issueShortId is defined; for bare latest it returns null.
  • The code falls through to validateAndRecoverEventId where skipValidation is true because eventId === LATEST_EVENT_SENTINEL, so @latest passes through unchanged.
  • resolveEventTarget then resolves the target and fetchMultipleEvents calls fetchEventWithContextgetEvent(org, project, '@latest').
  • getEvent uses getProjectEvent, which has no issue_id parameter; the API endpoint /projects/{org}/{project}/events/{event_id}/ does not accept 'latest' as a valid event ID.
  • The only endpoint that supports event_id: 'latest' is getOrganizationIssueEvent (used by getLatestEvent), which requires an issue_id — confirmed by the mock route at test/mocks/routes.ts:188 (/organizations/:orgSlug/issues/:issueId/events/latest/).
  • The same pattern exists in the two-arg path of parsePositionalArgs (line 390), where second.toLowerCase() === 'latest' also returns the sentinel without issueId.

Identified by Warden · find-bugs · XPM-5GF

@sentry sentry Bot changed the title fix(event): recognize numeric issue IDs and bare 'latest' in view command fix(event view): recognize numeric issue IDs and bare "latest" Jul 25, 2026
@sentry
sentry Bot marked this pull request as ready for review July 25, 2026 11:59
@github-actions github-actions Bot added the risk: high PR risk score: high label Jul 25, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 640d490. Configure here.

// Detect bare "latest" (without the "@" prefix sentinel).
if (eventId.toLowerCase() === "latest") {
return { eventId: LATEST_EVENT_SENTINEL, targetArg };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare "latest" never fetches an event

High Severity

Bare "latest" is rewritten to LATEST_EVENT_SENTINEL without an issueId or issueShortId. resolveIssueShortcut then returns null, and the command tries to load a project event whose ID is @latest, which the project events API does not support. There is no existing "latest event for a project" path to fall through to.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 640d490. Configure here.

// Detect numeric issue ID (e.g., "17370") — treat as issueId and fetch latest event.
if (ALL_DIGITS_RE.test(eventId)) {
return { eventId: LATEST_EVENT_SENTINEL, targetArg, issueId: eventId };
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numeric issue IDs skip org resolution

High Severity

Numeric issue IDs are parsed into issueId, but that path only reads an org when targetArg is OrgAll (issue URLs). Bare IDs leave auto-detect, and org/project 17370 stays Explicit, so resolveIssueShortcut calls resolveEffectiveOrg with an empty string and never uses DSN/config or the user’s org. The CLI-1F5 case still fails to fetch.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 640d490. Configure here.

Comment on lines +188 to 192
/** Matches strings composed entirely of decimal digits (numeric issue IDs). */
const ALL_DIGITS_RE = /^\d+$/;

/**
* Parse a single positional arg for event view, handling issue short ID

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Using sentry event view with a bare numeric issue ID or latest causes an API error because the organization context is not correctly resolved.
Severity: HIGH

Suggested Fix

Modify resolveIssueShortcut to correctly resolve the organization when an issueId is present but no explicit organization is provided. Instead of calling resolveEffectiveOrg with an empty string when parsed.type is auto-detect, it should use the default or cached organization from the user's configuration.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/commands/event/view.ts#L188-L192

Potential issue: When a user runs `sentry event view` with a bare numeric issue ID
(e.g., `sentry event view 12345`) or the `latest` keyword without an
organization/project context, the logic fails to resolve the correct organization. The
`parseSingleArg` function correctly identifies the issue ID but leaves the `targetArg`
as `undefined`. This leads to `resolveIssueShortcut` calling `resolveEffectiveOrg("")`
with an empty string. The function returns an empty string, which is then used as the
organization slug in the subsequent API call to fetch the event, resulting in a 404 Not
Found error from the Sentry API.

Also affects:

  • src/commands/event/view.ts:268~273

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants