From 24ca2cbbe5e5ce8a0832c9447d2626078b88eeb7 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 4 Dec 2026 12:00:28 +0800 Subject: [PATCH] refactor(cli): reuse owned result writes (#16573) --- src/cli/cliResultOutput.ts | 46 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/cli/cliResultOutput.ts b/src/cli/cliResultOutput.ts index e8917d58f98..8dea32af28e 100644 --- a/src/cli/cliResultOutput.ts +++ b/src/cli/cliResultOutput.ts @@ -646,9 +646,8 @@ export const createCliResultOutput = ( !options.tokenCount && format !== "json" && format !== "jsonl"; - if (format === "jsonl") { - handled = true; - try { + if (format === "jsonl") + return writeOwnedOutput(async () => { error = await writeCliJsonLines( { ...options, @@ -664,12 +663,7 @@ export const createCliResultOutput = ( }, destination, ); - } catch (cause: unknown) { - failed = true; - throw cause; - } - return true; - } + }); const meta = resultMeta(metadata); const errorDocument = envelopeFailed ? fullFailureEnvelope( @@ -802,27 +796,19 @@ export const createCliResultOutput = ( operationFailure === undefined ) return false; - handled = true; - try { - if (formattedText !== undefined) { - // Retain the complete owned projection at the output boundary. - await writeOutputText(destination, `${formattedText}\n`); - } else { - await writeJsonOutput( - error === undefined - ? document - : options.fullOutput - ? { ok: false, error, meta } - : error, - destination, - format as "json" | "jsonl", - ); - } - } catch (cause: unknown) { - failed = true; - throw cause; - } - return true; + return writeOwnedOutput(() => + formattedText !== undefined + ? writeOutputText(destination, `${formattedText}\n`) + : writeJsonOutput( + error === undefined + ? document + : options.fullOutput + ? { ok: false, error, meta } + : error, + destination, + format as "json" | "jsonl", + ), + ); } };