fix(log): handle org/log-id shorthand to prevent ContextError#1222
fix(log): handle org/log-id shorthand to prevent ContextError#1222sentry[bot] wants to merge 1 commit into
Conversation
|
| if (normalizedLogId) { | ||
| return { rawLogIds: [normalizedLogId], targetArg: `${org}/` }; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| const logSegment = first.slice(slashIdx + 1); | ||
| const normalizedLogId = logSegment && tryNormalizeHexId(logSegment); | ||
| if (normalizedLogId) { | ||
| return { rawLogIds: [normalizedLogId], targetArg: `${org}/` }; |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit bac9428. Configure here.
Codecov Results 📊✅ Patch coverage is 85.71%. Project has 5335 uncovered lines. Files with missing lines (1)
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 +1Generated by Codecov Action |


This PR fixes an issue where
sentry-cli log viewwould fail with aContextError: Log ID is required.when users provided a log ID in theorg/log-idshorthand format (e.g.,springfin/019f4a16...).The root cause was that
src/commands/log/view.tspassed this shorthand directly toparseSlashSeparatedArg(insrc/lib/arg-parsing.ts). This function incorrectly interpreted a single-slash argument asorg/projectwith a missing ID, leading to the error.The solution implements a guard in
src/commands/log/view.ts(within theparsePositionalArgsfunction, specifically in the single-argument handling branch) to detect and correctly parse theorg/log-idshorthand beforeparseSlashSeparatedArgis called. This approach mirrors the established pattern already present insrc/commands/event/view.tsandsrc/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.