fix(cua-driver-rs): CLI 'call' surfaces JSON parse errors with PS5.1 stdin-pipe hint (#1637, closes #1635) - #1642
Conversation
…'call' instead of silently falling back to stdin
`cua-driver call <tool> <json>` previously did
`pos.next().and_then(|s| serde_json::from_str(s).ok()).or_else(|| read_stdin_json())`
— the `.ok()` swallowed any parse error and silently fell back to stdin.
On PowerShell 5.1, native-command argv parsing strips quotes around JSON
field names in multi-field args (`'{"a":1,"b":2}'` arrives as `{a:1,b:2}`
which serde_json rejects). The fall-through reads from empty stdin →
tool sees `args = null` → emits a misleading "missing required field X"
error instead of the actual cause.
## Repro
PowerShell 5.1 (Windows 11 24H2):
```
PS> cua-driver call get_window_state '{"pid":9912,"window_id":197488}'
cua-driver.exe : Missing required integer field pid.
```
The JSON is fine; PS 5.1's argv parser mangled it. CLI silently absorbed
the parse failure.
After this PR:
```
PS> cua-driver call get_window_state '{"pid":9912,"window_id":197488}'
error: positional JSON arg to 'cua-driver call' did not parse: ...
received: {pid:9912,window_id:197488}
hint: PowerShell 5.1 strips quotes around JSON field names in
multi-field args. Pipe the JSON via stdin instead:
'{"pid":1234,"window_id":5678}' | cua-driver call get_window_state
Or use PowerShell 7+ (pwsh) which preserves the quotes.
```
Exit code 2 instead of silent failure with a downstream misleading error.
## Implementation
`crates/cua-driver/src/cli.rs`: replace `.and_then(...).or_else(...)`
with explicit `match` that differentiates "no positional arg" (fall back
to stdin) from "positional arg given but didn't parse" (emit clear error
+ stdin-pipe hint + exit 2). Applied to both the explicit `call`
subcommand path and the implicit `cua-driver <tool> <json>` path.
## Bonus: launch_app error message
The Swift-original error "Provide either bundle_id or name to identify
the app to launch." predated the Windows aumid/path/launch_path/urls
additions and made #1635 look like an aumid-specific bug. Updated to
"Provide one of: bundle_id, name, aumid, path, launch_path, or urls".
The actual cause of #1635 was the PS argv quote-stripping above; the
improved message just stops misleading anyone who hits the error for
unrelated reasons.
Closes #1637, closes #1635.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR improves error handling in the CLI and validation messages. JSON argument parsing in ChangesCLI Error Handling and Field Validation Messages
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ion all valid fields (#1635) Companion to the cli.rs fix in this PR. The Swift-original error message ("Provide either bundle_id or name") predated the Windows-specific additions to LaunchAppTool's resolver chain (aumid, path, launch_path, urls) and made #1635 look like an aumid-specific deserialization bug. The actual root cause of #1635 was the PS argv quote-stripping fixed by this PR's cli.rs change. The improved error message is defense-in-depth: if a user hits the missing-target case for unrelated reasons (e.g. empty args via stdin or a script that builds the JSON wrong), they get a list of every accepted field, not just the Swift-era subset. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
cua-driver call <tool> <json>used.and_then(|s| serde_json::from_str(s).ok()).or_else(stdin)which silently swallowed parse errors and fell back to stdin. On PowerShell 5.1, native-command argv parsing mangles multi-field JSON (strips quotes around field names) — the CLI never told the user. The tool's own required-field validator then emitted a misleading "missing field X" error.Fix
Differentiate "no positional arg" (legit stdin fallback) from "positional arg given but didn't parse" (emit clear error + stdin-pipe hint + exit 2). Applied to both
cua-driver call <tool>and the implicitcua-driver <tool>paths.Sample output after fix:
Also closes #1635
The launch_app error "Provide either bundle_id or name" was misleading — Windows resolver accepts
aumid,path,launch_path,urlstoo. The Swift-original message predated those additions. Now reads: "Provide one of: bundle_id, name, aumid, path, launch_path, or urls".Note: the actual root cause of #1635 (cuademo's
cua-driver call launch_app '{"aumid":"..."}'failing) is the PS argv quote-stripping fixed above. The error-message tweak just prevents future confusion when someone hits the error for unrelated reasons.Closes #1637, closes #1635.
🤖 Generated with Claude Code
Summary by CodeRabbit