Repository navigation
Show help for a bare ts dev proxy invocation #1063
Description
Running ts dev proxy with no arguments does not print help. It runs part of proxy startup, then fails with a debug-formatted error-stack report that exposes internal source locations.
Reproducing
On macOS (ts dev proxy is macOS-only):
$ cargo run -q -p trusted-server-cli --target aarch64-apple-darwin -- dev proxy
sudo: a password is required
warning: Safari: could not auto-restore the system proxy for 'Wi-Fi' (needs admin). ...
[ts] invalid rule configuration
├╴at crates/trusted-server-cli/src/commands/dev/proxy/mod.rs:256:41
│
╰─▶ no rewrite rule: pass --map FROM=TO (or -f/--from with -t/--to)
╰╴at crates/trusted-server-cli/src/commands/dev/proxy/config.rs:269:20
Two problems, and the second is not in the original report:
-
Internal paths leak.
dev/mod.rs:50renders the report withformat!("{report:?}"), so every user-facing proxy failure printserror-stackdebug output with file/line attachments. The underlying message ("no rewrite rule: pass --map FROM=TO") is already good; only the framing is wrong. -
Side effects run before the error.
runcallsbrowser::restore_system_proxy_if_pendingatmod.rs:254beforeconfig::resolveatmod.rs:256. So a bare invocation touches system proxy state and attemptssudobefore discovering it has no rule to serve. A user who typedts dev proxyto see what it does gets a sudo prompt.
Suggested approach
Set arg_required_else_help = true on ProxyArgs (proxy/mod.rs:81) so Clap prints help and exits before run is ever called. That fixes both problems at once, since nothing in run executes.
Watch the interaction with the nested subcommand: ProxyArgs carries command: Option<ProxySub> (mod.rs:150), which is how ts dev proxy ca install is reached. ts dev proxy ca … takes no rewrite rules and must keep working. Verify this by hand, not just by reading — the flag's behavior with an optional subcommand plus all-optional args is worth confirming empirically. If arg_required_else_help turns out to break the ca path, fall back to an explicit check at the top of run that prints help for the no-args, no-subcommand case.
Separately, consider whether dev/mod.rs:50 should render {report} rather than {report:?} for user-facing output. That is a slightly wider change — it affects every ts dev proxy error, not just this one — so it is acceptable to leave out and file separately if it grows.
Acceptance criteria
- A bare
ts dev proxyprints Clap help and exits without touching system proxy state, attemptingsudo, or printingerror-stackdebug output. ts dev proxy ca path,ca install,ca uninstall, andca regeneratestill work.- An incomplete-but-explicit invocation (for example
ts dev proxy --from a.example.comwith no--to) still produces the concise no-rule error, not help text. - A regression test covers the bare invocation.
no_rule_passed_is_a_no_rule_errorinproxy/config.rs:669is the neighboring test; a Clap-level test likely belongs with the otherArgs::try_parse_fromtests inrun.rs. cargo clippyand the CLI test suite pass.
Getting set up
ts dev proxy is macOS-only: its dependencies are cfg-scoped in Cargo.toml and the Proxy subcommand does not exist on other hosts. The workspace default target is wasm32-wasip1, so the CLI needs an explicit host target:
cargo run -p trusted-server-cli --target aarch64-apple-darwin -- dev proxy
./scripts/test-cli.sh
Pointers
crates/trusted-server-cli/src/commands/dev/proxy/mod.rs:81—ProxyArgscrates/trusted-server-cli/src/commands/dev/proxy/mod.rs:150— the optionalcasubcommand fieldcrates/trusted-server-cli/src/commands/dev/proxy/mod.rs:184—run, including thecaearly return and the ordering problemcrates/trusted-server-cli/src/commands/dev/proxy/config.rs:266—resolveandConfigError::NoRulecrates/trusted-server-cli/src/commands/dev/mod.rs:50— the{report:?}rendering
Activity
Add a first-issue section to the new-engineer setup page