Skip to content

ref(cli): Parse arity-dependent arguments in the scanner - #1714

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
byk/cli-bound-arguments
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
byk/cli-bound-arguments

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #1655 for #1564. Some positionals mean different things depending on how many arguments were given, like [<org>/<project>] <replay-id> or log list's optional trailing trace ID. Those kept parsing in func because a per-element Stricli parse only sees one argument and can't count the rest.

The new parser type. Our @stricli/core patch now lets an array positional declare combine. It receives every parsed element and returns the one value the command gets. If it throws, the error becomes an ArgumentParseError. Arity-dependent targets therefore fail in the scanner with exit 252, like every other argument. When combine is unset the patch does nothing, and check:patches checks that it is still present.

On top of the patch, boundArguments (src/lib/positional-parse.ts) builds the positional. It pairs a pure parse over all the arguments with a resolve that runs after the auth guard, the same contract as boundPositional. func takes one BoundArguments<Parsed, Resolved>, reads .parsed and awaits .resolved. Each element still completes as its completion kind.

Migrated: log list, replay view and replay download.

  • Parsing a pasted Sentry URL no longer applies its server. The parse returns baseUrl and any trace-target warnings, and resolve applies them.
  • parseTraceTargetInput and parseDualModeInput (trace-target.ts) are the side-effect-free trace parsers. parseTraceTarget and parseDualModeArgs now wrap them, so span and trace commands don't change in this PR.
  • Malformed input now exits 252 from the scanner: a bad replay ID, too many arguments, or a replay URL without an ID.
  • replay download gets org/project completion, which replay view already had.

Kept behavior:

  • If an argument is help, the parse error is deferred to func, so sentry replay view help still prints the command's help.
  • buildListCommand's subcommand-name interception (sentry log list view …) drops the first argument and parses the rest again.

Next: issue and dashboard targets, plus trace view/logs, span list/view and log view, fit the same [<org>/[<project>/]]<id> shape. They can each move onto boundArguments in follow-ups. The list-target positional for dispatch-based lists is in #1711, kept separate from this PR.

Verification (Node 24):

  • tsc, lint and check:patches pass.
  • CLI unit suite: 11,752 passed. The 7 failures are sandbox-only (root/permission tests and the delta-upgrade stable patch) and fail on main too.
  • Smoke-tested on a bundled build: replay view help, replay view acme/web 0123 (exit 252), replay download a b c (exit 252), and log list view <trace-id> (shows the interception tip, then parses the trace ID alone).

via BYK.

--

View Junior Session in Sentry

Follow-up to #1655 for #1564. Positionals whose meaning depends on how
many arguments were given (`[<org>/<project>] <replay-id>`, `log list`'s
trailing trace ID) kept parsing in `func`, because a per-element Stricli
`parse` can't see the count.

Our `@stricli/core` patch now lets an array positional declare
`combine`: it gets every parsed element and returns the one value the
command receives. A throw becomes an `ArgumentParseError`, so these
commands fail in the scanner with exit 252 like other arguments.
`boundArguments` (`src/lib/positional-parse.ts`) builds such a
positional: a pure `parse` over all the arguments, bound to a `resolve`
that runs after the auth guard, like `boundPositional`.

`log list`, `replay view` and `replay download` move onto it. Parsing a
pasted Sentry URL no longer applies its server; the parse returns
`baseUrl` (and trace-target warnings), and `resolve` applies them.
`parseTraceTargetInput` and `parseDualModeInput` are the side-effect-free
trace parsers; the existing ones wrap them, so span and trace commands
are unchanged and can migrate onto the same primitive next.

A parse error next to a `help` argument is deferred to `func`, so
`sentry replay view help` still shows the command's help. Plural alias
interception drops the first argument and parses the rest again.

Co-Authored-By: BYK <burak.kaya@sentry.io>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Oct 29, 2026 1:01am UTC

Request Review

@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 07f92a3. Configure here.

Comment thread packages/cli/src/commands/log/list.ts
Comment thread packages/cli/src/lib/list-command.ts Outdated
Addresses Bugbot on #1714. `buildListCommand` dropped a subcommand name
(`sentry log list view …`) in `func` and parsed the other arguments
again, after the scanner had already parsed all of them:

- `log list view acme/web <trace-id>` failed in the scanner (exit 252),
  because "acme/web" was read as the trace ID, so the intercept never ran
- a parse error deferred next to `help` in the second parse was never
  thrown, so `func` read an undefined parse

`skipLeadingArgument` now wraps a `boundArguments` positional so the
name is left out in the scanner, before it changes what the other
arguments mean. `func` only prints the hint.

This branch was previously deployed

1 inactive deployment
Preview — 1fa4eff9 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants