Skip to content

ref(cli): Parse target positionals in Stricli's argument scanner - #1655

Merged
BYK merged 2 commits into
mainfrom
byk/cli-eager-target-parse
Oct 25, 2026
Merged

BYK merged 2 commits into
mainfrom
byk/cli-eager-target-parse

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Refs #1564. Replaces #1651.

Per the review on #1651, this drops the special handling that kept a CliError's exit code when an argument fails to parse. Target positionals no longer parse lazily inside func. Stricli parses them in its argument scanner, so an invalid target now fails like a bad flag: Failed to parse "<input>" for <placeholder>: … and exit code 252. Only resolution is still deferred, to the first target.resolved read. target.parsed, target.resolved and target.raw behave as before for commands, and no command changes beyond a comment.

Changes:

  • positional-parse.ts: lazyPositional/LazyPositional become boundPositional/BoundPositional. The parse runs when Stricli calls the parser. resolved stays memoized and runs inside func, after the auth guard.
  • No side effects in the parse. It now runs before the auth guard, and it also runs when a later argument fails to parse. parseOrgProjectInput is the pure half of parseOrgProjectArg: it returns a pasted Sentry URL's server instead of applying it. The target resolver applies that server, so a URL for a server you have no account on still fails with HostScopeError (exit 13) after the auth guard. parseOrgProjectArg itself is unchanged for its other callers.
  • Destructive check. buildCommand checks the targets of destructive commands after the auth guard and rc URL check, before func runs. Before, the check only ran inside target.resolved, so a destructive command that read only target.parsed would skip it.
  • Docs. exit-codes.md gains a 252 row and an "Argument errors" section, and code 21 no longer claims bad flag values. The agent guidance and the generated skill get a 252 row, and the CLI AGENTS.md and the lint rule message describe the new flow.

Tests:

  • test/lib/positional-parse.test.ts covers: an invalid target exits with InvalidArgument; a destructive command refuses auto-detect even when it only reads parsed; awaiting a target does not resolve it; and a pasted URL's server is applied on resolve, not on parse.
  • test/lib/scanner-flags.integration.test.ts runs the real app: issue list --period bogus and trace list @latest both exit with InvalidArgument.
  • lint and typecheck pass. Full test:unit: 11336 passed, 6 failed. The 6 are chmod-based permission tests that also fail on clean main in this sandbox, which runs as a user that bypasses chmod.

via BYK.

--

View Junior Session in Sentry

Target positionals no longer parse lazily inside `func`. Stricli runs the
parse in its argument scanner, so an invalid target fails like any other
argument: "Failed to parse ..." and exit code 252, the same as flags.
Only resolution stays deferred, on the first `target.resolved` read.

The parse is now free of side effects: the server of a pasted Sentry URL is
applied when the target resolves, after the auth guard and rc URL check, so
a host-scope failure still exits 13. `parseOrgProjectInput` is the pure
half of `parseOrgProjectArg`.

Destructive commands check their targets in `buildCommand` before `func`
runs, so an auto-detected target is refused whether the command reads
`parsed` or `resolved`.

The exit code docs now describe argument errors (252) and no longer list
bad flag values under 21.

Refs #1564

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

vercel Bot commented Oct 25, 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 25, 2026 3:39pm UTC

Request Review

Comment thread apps/cli-docs/src/content/docs/exit-codes.md
Arguments Stricli cannot parse exit 252 without reaching reportCliError,
so they went unseen. `exceptionWhileParsingArguments` now reports each one
as an `invalid_argument` info message, grouped into one issue like
`unknown_command`, with the scanner error class, the parser's error class,
and the redacted message the user saw.

Refs #1564

Co-Authored-By: BYK <burak.kaya@sentry.io>
@BYK
BYK merged commit 5a574eb into main Oct 25, 2026
26 checks passed
@BYK
BYK deleted the byk/cli-eager-target-parse branch October 25, 2026 15:57

This branch was previously deployed

1 inactive deployment
Preview — c94c4fea Deployed Oct 25, 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.

1 participant