paritytech / paritytech/polkadot-cli

Error output ignores `--json` flag — should emit JSON envelope

Open Beginner friendly
#163 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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:

  1. Emit {"error": "<message>"} to stdout (maintaining the contract that all JSON goes to stdout)
  2. Keep the non-zero exit code
  3. Optionally still log human-readable text to stderr for terminal users

Key Files

  • src/cli.tshandleError() error handler
  • src/core/output.ts — output utilities

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.