Skip to content

Commit fb52715

Browse files
committed
fix(util): type a synchronous spawn refusal through the PlatformError channel
launch() can throw synchronously (e.g. EPERM from uv_spawn on Windows); launchProcess only mapped the async error event to a PlatformError, so the throw escaped the Effect.callback as a defect that no caller's typed-failure handling sees — the failure mode behind the Snapshot.capture step death in anomalyco#58685. Wrap the launch call and resume through the same toPlatformError path, so every caller gets the typed failure its handlers already recover. Reviewed-by-direction from the retained patch.
1 parent c96543a commit fb52715

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎packages/core/src/snapshot.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ const layer = Layer.effect(
144144
return ID.make(tree)
145145
}).pipe(
146146
Effect.catch((cause) => Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined))),
147-
// A spawn failure (e.g. EPERM on Windows) arrives as a defect, not a typed failure, and would
148-
// otherwise fail the whole step for this best-effort capture.
149-
Effect.catchDefect((cause) =>
150-
Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined)),
151-
),
152147
)
153148
})
154149

‎packages/util/src/cross-spawn-spawner.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,16 @@ const makeCrossSpawnSpawner = Effect.gen(function* () {
386386
Effect.callback<Spawned, PlatformError.PlatformError>((resume) => {
387387
const closed = Deferred.makeUnsafe<readonly [code: number | null, signal: NodeJS.Signals | null]>()
388388
const exited = Deferred.makeUnsafe<readonly [code: number | null, signal: NodeJS.Signals | null]>()
389-
const proc = launch(file, command.args.map(unwrap), opts)
389+
// A spawn refusal (e.g. EPERM from uv_spawn) throws synchronously; only the async `error` event
390+
// reaches the typed handler below, so map the throw through the same PlatformError here — otherwise
391+
// it escapes the callback as a defect and no caller's typed-failure handling sees it.
392+
let proc: NodeChildProcess.ChildProcess
393+
try {
394+
proc = launch(file, command.args.map(unwrap), opts)
395+
} catch (err) {
396+
resume(Effect.fail(toPlatformError("spawn", toError(err), command)))
397+
return Effect.void
398+
}
390399
let settle = () => {}
391400
let end = false
392401
let exit: readonly [code: number | null, signal: NodeJS.Signals | null] | undefined

0 commit comments

Comments
 (0)