Preserve waited app launch exit errors

- Map spawn failures before nonzero-exit checks in desktop launcher
- Add regression coverage for waited direct app launches on Linux
This commit is contained in:
Julius Marminge committed 2026-03-31 11:34:21 -07:00
1 parent 7fa5304e87
commit 439e8bcd42
2 files changed
+36 -3

No files matched your search

@@ -547,6 +547,39 @@ it.effect("openBrowser detaches direct app launches on win32 when not waiting",
}).pipe(Effect.provide(NodeFileSystem.layer)),
);
it.effect("openBrowser preserves non-zero exit errors for waited direct app launches", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-open-browser-linux-app-wait-" });
yield* writeExecutable(`${dir}/firefox`);
const calls: Array<SpawnCall> = [];
const open = yield* runOpen(
{
platform: "linux",
env: { PATH: dir },
},
spawnHarness(calls, () => ({ code: 23 })),
readOpen,
);
const error = yield* open
.openBrowser("https://example.com", {
wait: true,
app: { name: "firefox" },
})
.pipe(Effect.flip);
assert.equal(error._tag, "DesktopLauncherNonZeroExitError");
if (error._tag !== "DesktopLauncherNonZeroExitError") {
throw new Error(`Unexpected error tag: ${error._tag}`);
}
assert.equal(error.exitCode, 23);
assert.equal(error.command, `${dir}/firefox`);
assert.deepEqual(error.args, ["https://example.com"]);
}).pipe(Effect.provide(NodeFileSystem.layer)),
);
it.effect("openBrowser falls back from WSL PowerShell to xdg-open", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
@@ -703,6 +703,9 @@ export const make = Effect.fn("makeDesktopLauncher")(function* (
handle: ChildProcessSpawner.ChildProcessHandle,
) =>
handle.exitCode.pipe(
Effect.mapError((cause) =>
makeSpawnError(context, spawnInput.command, spawnInput.args, cause),
),
Effect.flatMap((exitCode) =>
!plan.allowNonzeroExitCode && exitCode !== 0
? Effect.fail(
@@ -710,9 +713,6 @@ export const make = Effect.fn("makeDesktopLauncher")(function* (
)
: Effect.void,
),
Effect.mapError((cause) =>
makeSpawnError(context, spawnInput.command, spawnInput.args, cause),
),
);
const runWaitedPlan = (