Skip to content

fix(log): handle org/log-id shorthand to prevent ContextError#1222

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/log-view-shorthand
Open

fix(log): handle org/log-id shorthand to prevent ContextError#1222
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/log-view-shorthand

Conversation

@sentry

@sentry sentry Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This PR fixes an issue where sentry-cli log view would fail with a ContextError: Log ID is required. when users provided a log ID in the org/log-id shorthand format (e.g., springfin/019f4a16...).

The root cause was that src/commands/log/view.ts passed this shorthand directly to parseSlashSeparatedArg (in src/lib/arg-parsing.ts). This function incorrectly interpreted a single-slash argument as org/project with a missing ID, leading to the error.

The solution implements a guard in src/commands/log/view.ts (within the parsePositionalArgs function, specifically in the single-argument handling branch) to detect and correctly parse the org/log-id shorthand before parseSlashSeparatedArg is called. This approach mirrors the established pattern already present in src/commands/event/view.ts and src/commands/replay/view.ts, ensuring consistent behavior across similar commands.

Fixes CLI-1AK

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

@github-actions github-actions Bot added the risk: high PR risk score: high label Jul 10, 2026
@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-1222/

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

Comment thread src/commands/log/view.ts
Comment on lines +117 to +119
if (normalizedLogId) {
return { rawLogIds: [normalizedLogId], targetArg: `${org}/` };
}

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: The new org/log-id shorthand for log view incorrectly generates a target that resolveTarget rejects, as it requires a specific project and receives an org-all type.
Severity: HIGH

Suggested Fix

The resolveTarget function in log/view.ts should be updated to handle the org-all case generated by the new shorthand. Instead of throwing an error, it should attempt to resolve the project, possibly by using a function similar to resolveOrgOptionalProjectFromArg used in replay/view.ts or by implementing logic to auto-detect the project when only an organization is provided with a log ID.

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/log/view.ts#L117-L119

Potential issue: The fix introduces a shorthand format `org/log-id` for the `log view`
command. When this shorthand is used, the code generates a `targetArg` like `org/`. This
is parsed into an `org-all` type, indicating an organization without a specific project.
However, the `resolveTarget` function for `log view` explicitly throws a `ContextError`
for `org-all` types because it requires both an organization and a project to function.
Consequently, using the new shorthand will cause the command to fail with a "Specific
project is required" error, making the new feature non-functional.

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

@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 1 potential issue.

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 bac9428. Configure here.

Comment thread src/commands/log/view.ts
const logSegment = first.slice(slashIdx + 1);
const normalizedLogId = logSegment && tryNormalizeHexId(logSegment);
if (normalizedLogId) {
return { rawLogIds: [normalizedLogId], targetArg: `${org}/` };

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.

Org log shorthand hits project error

Medium Severity

Single-argument org/log-id shorthand now sets targetArg to `${org}/`, which parseOrgProjectArg treats as org-all. resolveTarget always rejects org-all for log view, so the command still fails for the exact input this PR targets—only the ContextError message changes from “Log ID” to “Specific project”.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bac9428. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 85.71%. Project has 5335 uncovered lines.
✅ Project coverage is 81.82%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/commands/log/view.ts 85.71% ⚠️ 1 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.82%    81.82%        —%
==========================================
  Files          423       423         —
  Lines        29343     29350        +7
  Branches     19117     19125        +8
==========================================
+ Hits         24009     24015        +6
- Misses        5334      5335        +1
- Partials      1988      1989        +1

Generated by Codecov Action

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