From f4095ee3eb2e45ff2bf8f13e612f43105a4fe379 Mon Sep 17 00:00:00 2001 From: Huanqi Cao Date: Mon, 3 Aug 2026 23:58:57 +0800 Subject: [PATCH] fix(picker): end the closed worker-message switch in assertNever MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The driver's switch over Win32DialogWorkerMessage handled all three current kinds but had no default, so a fourth kind added to the worker protocol would compile cleanly and silently no-op — settle() never called and the pick dangles until worker exit. Add the local assertNever backstop (the command-compact shape; this package does not depend on dsh-llm for the helper) and the return the error case needs to avoid falling into it. Round-five review finding. --- .../host/directory-picker-native/src/win32-dialog.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/host/directory-picker-native/src/win32-dialog.ts b/packages/host/directory-picker-native/src/win32-dialog.ts index a3aee2268a..15de82373e 100644 --- a/packages/host/directory-picker-native/src/win32-dialog.ts +++ b/packages/host/directory-picker-native/src/win32-dialog.ts @@ -51,6 +51,13 @@ const CLOSE_RETRY_MS = 150 /** Abort-service attempts before force-terminating the worker. */ const CLOSE_MAX_ATTEMPTS = 20 +/** Fail loudly if the closed worker-to-driver union gains an unhandled member. */ +/* v8 ignore start -- closed-union backstop; unreachable without a TypeScript contract violation */ +function assertNever(value: never): never { + throw new TypeError(`unknown win32 dialog worker message kind: ${String(value)}`) +} +/* v8 ignore stop */ + /** * Open the modern Win32 folder picker off the event loop. * @param signal - caller lifetime; abort closes the dialog and rejects. @@ -133,6 +140,10 @@ export async function pickWin32Directory( settle(() => { reject(new Error(`win32 folder dialog failed: ${message.message}`)) }) + return + /* v8 ignore next 2 -- closed worker-owned union; a fourth kind becomes a compile error */ + default: + assertNever(message) } }) worker.on('error', (error: Error) => {