From 79f818e8a28d0e749342b797daf8b9d447681a00 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 1 Mar 2026 12:55:15 -0800 Subject: [PATCH] Status scan: guard deferred promise rejections --- src/commands/status.scan.ts | 38 +++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/commands/status.scan.ts b/src/commands/status.scan.ts index 3a15bdf76..696f84411 100644 --- a/src/commands/status.scan.ts +++ b/src/commands/status.scan.ts @@ -26,6 +26,22 @@ type MemoryPluginStatus = { reason?: string; }; +type DeferredResult = { ok: true; value: T } | { ok: false; error: unknown }; + +function deferResult(promise: Promise): Promise> { + return promise.then( + (value) => ({ ok: true, value }), + (error: unknown) => ({ ok: false, error }), + ); +} + +function unwrapDeferredResult(result: DeferredResult): T { + if (!result.ok) { + throw result.error; + } + return result.value; +} + function resolveMemoryPluginStatus(cfg: ReturnType): MemoryPluginStatus { const pluginsEnabled = cfg.plugins?.enabled !== false; if (!pluginsEnabled) { @@ -202,13 +218,15 @@ export async function scanStatus( runExec(cmd, args, { timeoutMs: 1200, maxBuffer: 200_000 }), ).catch(() => null); const updateTimeoutMs = opts.all ? 6500 : 2500; - const updatePromise = getUpdateCheckResult({ - timeoutMs: updateTimeoutMs, - fetchGit: true, - includeRegistry: true, - }); - const agentStatusPromise = getAgentLocalStatuses(); - const summaryPromise = getStatusSummary(); + const updatePromise = deferResult( + getUpdateCheckResult({ + timeoutMs: updateTimeoutMs, + fetchGit: true, + includeRegistry: true, + }), + ); + const agentStatusPromise = deferResult(getAgentLocalStatuses()); + const summaryPromise = deferResult(getStatusSummary()); progress.tick(); progress.setLabel("Checking Tailscale…"); @@ -220,11 +238,11 @@ export async function scanStatus( progress.tick(); progress.setLabel("Checking for updates…"); - const update = await updatePromise; + const update = unwrapDeferredResult(await updatePromise); progress.tick(); progress.setLabel("Resolving agents…"); - const agentStatus = await agentStatusPromise; + const agentStatus = unwrapDeferredResult(await agentStatusPromise); progress.tick(); progress.setLabel("Probing gateway…"); @@ -293,7 +311,7 @@ export async function scanStatus( progress.tick(); progress.setLabel("Reading sessions…"); - const summary = await summaryPromise; + const summary = unwrapDeferredResult(await summaryPromise); progress.tick(); progress.setLabel("Rendering…");