diff --git a/apps/cli/tests/helpers/cli.ts b/apps/cli/tests/helpers/cli.ts index 7a853d1976..56b7d0a229 100644 --- a/apps/cli/tests/helpers/cli.ts +++ b/apps/cli/tests/helpers/cli.ts @@ -393,17 +393,43 @@ export function spawnSupabase( closeWaiters.clear(); }); + let stdinError: unknown; if (options?.stdin !== undefined && proc.stdin) { + proc.stdin.on("error", (error) => { + if (!("code" in error && error.code === "EPIPE")) { + stdinError = error; + } + }); proc.stdin.write(options.stdin); proc.stdin.end(); } + const stdinFailure = (result: RunResult) => + new Error( + [ + `stdin write to the CLI failed`, + `Command: supabase ${args.join(" ")}`, + `PID: ${proc.pid ?? ""}`, + `exit code: ${result.exitCode}${ + result.timedOutAfterMs === undefined + ? "" + : ` (no exit within ${result.timedOutAfterMs}ms, SIGKILLed by the harness)` + }`, + outputTail("stdout tail", result.stdout), + outputTail("stderr tail", result.stderr), + ].join("\n\n"), + { cause: stdinError }, + ); + const waitForExit = async ( timeoutMs = options?.exitTimeoutMs ?? DEFAULT_EXIT_TIMEOUT_MS, ): Promise => { if (closeResult) { cleanupProcessGroupOnClose(); disposeOwnHome(); + if (stdinError !== undefined) { + throw stdinFailure(closeResult); + } return closeResult; } @@ -429,6 +455,9 @@ export function spawnSupabase( }); disposeOwnHome(); + if (stdinError !== undefined) { + throw stdinFailure(timedOut ? { ...result, timedOutAfterMs: timeoutMs } : result); + } return timedOut ? { ...result, timedOutAfterMs: timeoutMs } : result; }; diff --git a/packages/config/scripts/build.ts b/packages/config/scripts/build.ts index 0aaec37bc8..8c6e63d5fa 100644 --- a/packages/config/scripts/build.ts +++ b/packages/config/scripts/build.ts @@ -71,8 +71,14 @@ async function renderJsonSchema(outputPath: string, json: Record( // is one runtime port away — don't rely on the buffering behavior. const stdoutText = new Response(proc.stdout).text(); const stderrText = new Response(proc.stderr).text(); - await proc.stdin.write(`${hashes.join("\n")}\n`); - await proc.stdin.end(); + try { + await proc.stdin.write(`${hashes.join("\n")}\n`); + await proc.stdin.end(); + } catch (error) { + if (!(error instanceof Error && "code" in error && error.code === "EPIPE")) { + throw error; + } + } const [exitCode, stdout, stderr] = await Promise.all([proc.exited, stdoutText, stderrText]); if (exitCode !== 0) {