paritytech / paritytech/polkadot-cli
Error output ignores `--json` flag — should emit JSON envelope
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10
- Forks
- 2
- Avg merge
- 12h 35m
- Merged PRs (30d)
- 4
Description
Problem
When --json is passed and a command fails, errors are output as plain text to stderr instead of JSON:
$ dot --rpc wss://... query.AssetConversion.Pools --dump --json
Error: Unknown pallet "AssetConversion".
This breaks the --json contract — scripts cannot reliably parse error output.
Expected Behavior
When --json is passed, errors should also be valid JSON:
{"error": "Unknown pallet \"AssetConversion\""}
With the process still exiting non-zero so scripts can check $?.
Root Cause
handleError() in src/cli.ts always uses console.error() with plain text formatting, regardless of whether --json was passed. The error handler currently has no access to the parsed CLI options.
Suggested Fix
Store the --json/--output flag in a module-level variable (or lightweight process-level context) that handleError() can access. When JSON mode is active:
- Emit
{"error": "<message>"}to stdout (maintaining the contract that all JSON goes to stdout) - Keep the non-zero exit code
- Optionally still log human-readable text to stderr for terminal users
Key Files
src/cli.ts—handleError()error handlersrc/core/output.ts— output utilities
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/cli.ts by tracing handleError() and how parsed CLI options are available, then read src/core/output.ts for existing output conventions. Verify that --json failures emit a JSON error envelope on stdout, preserve a non-zero exit code, and keep normal text behavior when JSON mode is not active.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100