fix(picker): end the closed worker-message switch in assertNever

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.
This commit is contained in:
Huanqi Cao
2026-08-05 00:31:43 +08:00
parent 020ce50414
commit f4095ee3eb
@@ -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) => {