From c781add3e4ee2972be81190be31ff7b78ed8cc3d Mon Sep 17 00:00:00 2001 From: nghetienhiep <13849419+nghetienhiep@users.noreply.github.com> Date: Wed, 15 Jul 2026 08:16:23 +0000 Subject: [PATCH] fix(miner): honor --json on the manage-poll --dry-run failure path Closes #6054 The --dry-run branch's catch block in runManagePoll wrote plain text to stderr on failure regardless of --json, unlike the non-dry-run path which already routes through reportCliFailure/describeCliError. Route the dry-run catch through the same helpers so --dry-run --json emits a parseable {ok:false,error} object on stdout, matching every other command's --json error contract in this CLI. --- packages/loopover-miner/lib/manage-poll.js | 3 +-- test/unit/miner-manage-poll.test.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/loopover-miner/lib/manage-poll.js b/packages/loopover-miner/lib/manage-poll.js index d750e4f918..7eeac642b0 100644 --- a/packages/loopover-miner/lib/manage-poll.js +++ b/packages/loopover-miner/lib/manage-poll.js @@ -206,8 +206,7 @@ export async function runManagePoll(args = [], options = {}) { } return 0; } catch (error) { - console.error(error instanceof Error ? error.message : String(error)); - return 2; + return reportCliFailure(parsed.json, describeCliError(error)); } } diff --git a/test/unit/miner-manage-poll.test.ts b/test/unit/miner-manage-poll.test.ts index 471bcef021..32f1ad283e 100644 --- a/test/unit/miner-manage-poll.test.ts +++ b/test/unit/miner-manage-poll.test.ts @@ -224,6 +224,27 @@ describe("loopover-miner manage poll (#2323/#2325)", () => { expect(error).toHaveBeenCalledWith("github_404: not found"); }); + it("#6054: --dry-run --json reports poll failures as a parseable {ok:false,error} object", async () => { + const initPortfolioQueue = vi.fn(); + const initEventLedger = vi.fn(); + const pollCheckRuns = vi.fn().mockRejectedValue(new Error("github_404: not found")); + const log = vi.spyOn(console, "log").mockImplementation(() => undefined); + + expect( + await runManagePoll(["acme/widgets", "4", "--dry-run", "--json"], { + initPortfolioQueue, + initEventLedger, + pollCheckRuns, + }), + ).toBe(2); + expect(initPortfolioQueue).not.toHaveBeenCalled(); + expect(initEventLedger).not.toHaveBeenCalled(); + expect(JSON.parse(String(log.mock.calls[0]?.[0]))).toEqual({ + ok: false, + error: "github_404: not found", + }); + }); + it("#4847: --dry-run stringifies a thrown non-Error value instead of crashing", async () => { const pollCheckRuns = vi.fn().mockRejectedValue("raw_string_fault"); const error = vi.spyOn(console, "error").mockImplementation(() => undefined);