spawnSync shouldn't throw (#15561)

Co-authored-by: Meghan Denny <meghan@bun.sh>
This commit is contained in:
Jarred Sumner
2024-12-03 19:26:36 -08:00
committed by GitHub
parent d27594ecf4
commit 0d5e4e162b
4 changed files with 51 additions and 18 deletions

View File

@@ -558,20 +558,27 @@ function spawnSync(file, args, options) {
}
}
const {
stdout = null,
stderr = null,
success,
exitCode,
signalCode,
} = Bun.spawnSync({
cmd: options.args,
env: options.env || undefined,
cwd: options.cwd || undefined,
stdio: bunStdio,
windowsVerbatimArguments: options.windowsVerbatimArguments,
windowsHide: options.windowsHide,
});
var error;
try {
var {
stdout = null,
stderr = null,
success,
exitCode,
signalCode,
} = Bun.spawnSync({
cmd: options.args,
env: options.env || undefined,
cwd: options.cwd || undefined,
stdio: bunStdio,
windowsVerbatimArguments: options.windowsVerbatimArguments,
windowsHide: options.windowsHide,
});
} catch (err) {
error = err;
stdout = null;
stderr = null;
}
const result = {
signal: signalCode ?? null,
@@ -580,6 +587,10 @@ function spawnSync(file, args, options) {
output: [null, stdout, stderr],
};
if (error) {
result.error = error;
}
if (stdout && encoding && encoding !== "buffer") {
result.output[1] = result.output[1]?.toString(encoding);
}
@@ -591,8 +602,11 @@ function spawnSync(file, args, options) {
result.stdout = result.output[1];
result.stderr = result.output[2];
if (!success) {
if (!success && error == null) {
result.error = new SystemError(result.output[2], options.file, "spawnSync", -1, result.status);
}
if (result.error) {
result.error.spawnargs = ArrayPrototypeSlice.$call(options.args, 1);
}