Skip to content

fix(miner): discover-cli.js --dry-run doesn't honor --json on failure #6053

Description

@JSONbored

Context

This repo has an established JSON error-contract convention for CLIs (packages/loopover-miner/lib/cli-error.js's reportCliFailure): when --json is set, a failure emits a parseable { ok: false, error } object on stdout instead of plain text on stderr. Two other commands in this exact family were just fixed for this same bug (#5914/#6034, #6033).

packages/loopover-miner/lib/discover-cli.js's runDiscover has the same bug in its --dry-run branch. The non-dry-run failure path correctly calls reportCliFailure(parsed.json, ...) (a few lines below, in the main flow), but the --dry-run branch's own catch block does a raw, unconditional:

} catch (error) {
  console.error(error instanceof Error ? error.message : String(error));
  return 2;
}

So loopover-miner discover --dry-run --json on a fetch/rank failure prints plain text to stderr instead of parseable JSON to stdout — breaking any --json-consuming caller (CI, the MCP wrapper, a script) exactly when it most needs a structured error. test/unit/miner-discover-cli.test.ts's two "--dry-run reports fan-out failures" tests only exercise the non---json case, so this combination is untested today.

Requirements

  • The --dry-run branch's catch block in runDiscover (packages/loopover-miner/lib/discover-cli.js) must call reportCliFailure(parsed.json, describeCliError(error)) (or the equivalent already used by this file's non-dry-run path) instead of the raw console.error/return 2.
  • Behavior for the non---json case must be unchanged (plain-text stderr output stays plain text).
  • Do not touch any other command's --dry-run handling in this PR — this issue is scoped to discover-cli.js only.

Deliverables

  • runDiscover's --dry-run catch block honors --json the same way the non-dry-run path already does
  • Test: loopover-miner discover --dry-run --json on a fetch/rank failure emits {ok:false,error} parseable JSON on stdout, exit code unchanged
  • Test: the existing non---json --dry-run failure tests still pass unmodified

Test Coverage Requirements

99%+ patch coverage (branch-counted) on the changed branch in discover-cli.js.

Expected Outcome

loopover-miner discover --dry-run --json on any fetch/rank failure prints valid, parseable {ok:false,error} JSON on stdout — matching every other command's --json error contract in this package.

Links & Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions