Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions apps/cli/tests/helpers/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Comment thread
7ttp marked this conversation as resolved.
proc.stdin.write(options.stdin);
proc.stdin.end();
}
Comment thread
7ttp marked this conversation as resolved.

const stdinFailure = (result: RunResult) =>
new Error(
[
`stdin write to the CLI failed`,
`Command: supabase ${args.join(" ")}`,
`PID: ${proc.pid ?? "<unknown>"}`,
`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<RunResult> => {
if (closeResult) {
cleanupProcessGroupOnClose();
disposeOwnHome();
if (stdinError !== undefined) {
throw stdinFailure(closeResult);
}
return closeResult;
}

Expand All @@ -429,6 +455,9 @@ export function spawnSupabase(
});

disposeOwnHome();
if (stdinError !== undefined) {
throw stdinFailure(timedOut ? { ...result, timedOutAfterMs: timeoutMs } : result);
}
return timedOut ? { ...result, timedOutAfterMs: timeoutMs } : result;
};

Expand Down
10 changes: 8 additions & 2 deletions packages/config/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ async function renderJsonSchema(outputPath: string, json: Record<string, unknown
stdout: "pipe",
stderr: "pipe",
});
await formatter.stdin.write(schema);
await formatter.stdin.end();
try {
await formatter.stdin.write(schema);
await formatter.stdin.end();
} catch (error) {
if (!(error instanceof Error && "code" in error && error.code === "EPIPE")) {
throw error;
}
}

const [exitCode, formatted, stderr] = await Promise.all([
formatter.exited,
Expand Down
10 changes: 8 additions & 2 deletions packages/config/scripts/semantic-release-path-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ export async function filterCommitsToPackage<T extends { hash: string }>(
// 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) {
Expand Down