aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/child_process.exports.js4
-rw-r--r--test/bun.js/child_process-node.test.js16
-rw-r--r--test/bun.js/spawned-child.js4
3 files changed, 16 insertions, 8 deletions
diff --git a/src/bun.js/child_process.exports.js b/src/bun.js/child_process.exports.js
index 7af8bdebd..71d97366a 100644
--- a/src/bun.js/child_process.exports.js
+++ b/src/bun.js/child_process.exports.js
@@ -290,7 +290,9 @@ export function execFile(file, args, options, callback) {
if (args?.length) cmd += ` ${ArrayPrototypeJoin.call(args, " ")}`;
if (!ex) {
- ex = genericNodeError(`Command failed: ${cmd}\n${stderr}`, {
+ let message = `Command failed: ${cmd}`;
+ if (stderr) message += `\n${stderr}`;
+ ex = genericNodeError(message, {
// code: code < 0 ? getSystemErrorName(code) : code, // TODO: Add getSystemErrorName
code: code,
killed: child.killed || killed,
diff --git a/test/bun.js/child_process-node.test.js b/test/bun.js/child_process-node.test.js
index 664fc8f8b..a225172ce 100644
--- a/test/bun.js/child_process-node.test.js
+++ b/test/bun.js/child_process-node.test.js
@@ -170,7 +170,7 @@ describe("ChildProcess spawn bad stdio", () => {
// Monkey patch spawn() to create a child process normally, but destroy the
// stdout and stderr streams. This replicates the conditions where the streams
// cannot be properly created.
- function createChild(options, callback, done) {
+ function createChild(options, callback, done, target) {
var __originalSpawn = ChildProcess.prototype.spawn;
ChildProcess.prototype.spawn = function () {
const err = __originalSpawn.apply(this, arguments);
@@ -182,13 +182,14 @@ describe("ChildProcess spawn bad stdio", () => {
};
const { mustCall } = createCallCheckCtx(done);
- const cmd = `bun ${__dirname}/spawned-child.js`;
+ let cmd = `bun ${import.meta.dir}/spawned-child.js`;
+ if (target) cmd += " " + target;
const child = exec(cmd, options, mustCall(callback));
ChildProcess.prototype.spawn = __originalSpawn;
return child;
}
- it.skip("should handle normal execution of child process", (done) => {
+ it("should handle normal execution of child process", (done) => {
createChild(
{},
(err, stdout, stderr) => {
@@ -200,16 +201,19 @@ describe("ChildProcess spawn bad stdio", () => {
);
});
- it.skip("should handle error event of child process", (done) => {
- const error = new Error("foo");
+ it("should handle error event of child process", (done) => {
+ const error = new Error(
+ `Command failed: bun ${import.meta.dir}/spawned-child.js ERROR`,
+ );
createChild(
{},
(err, stdout, stderr) => {
- strictEqual(err, error);
+ strictEqual(err.message, error.message);
strictEqual(stdout, "");
strictEqual(stderr, "");
},
done,
+ "ERROR",
);
});
diff --git a/test/bun.js/spawned-child.js b/test/bun.js/spawned-child.js
index d39131933..738d42f7e 100644
--- a/test/bun.js/spawned-child.js
+++ b/test/bun.js/spawned-child.js
@@ -22,6 +22,8 @@ if (TARGET === "STDIN") {
});
} else if (TARGET === "STDOUT") {
process.stdout.write("stdout_test");
+} else if (TARGET === "ERROR") {
+ console.log("oops");
} else {
- console.log("unknown target! you messed up...");
+ // nothing
}