mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
spawnSync shouldn't throw (#15561)
Co-authored-by: Meghan Denny <meghan@bun.sh>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user