diff options
author | 2022-11-10 19:50:35 -0800 | |
---|---|---|
committer | 2022-11-10 19:50:35 -0800 | |
commit | a1e786011d955933a10a295089b64b57c328ed33 (patch) | |
tree | 3b5a36d47c63eef3156726e781d1affbcf8d50a7 /src | |
parent | 7b4c8802a1dd97c516623ed9950e2fa27ff88cf3 (diff) | |
download | bun-a1e786011d955933a10a295089b64b57c328ed33.tar.gz bun-a1e786011d955933a10a295089b64b57c328ed33.tar.zst bun-a1e786011d955933a10a295089b64b57c328ed33.zip |
[bun run] Fix potential crash when a command terminates abnormally
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/run_command.zig | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 6b5946764..161b1362b 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -313,10 +313,23 @@ pub const RunCommand = struct { Output.prettyErrorln("<r><red>error<r>: Failed to run \"<b>{s}<r>\" due to error <b>{s}<r>", .{ std.fs.path.basename(executable), @errorName(err) }); Global.exit(1); }; - - if (result.Exited > 0) { - Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" exited with {d} status<r>", .{ std.fs.path.basename(executable), result.Exited }); - Global.exit(result.Exited); + switch (result) { + .Exited => |code| { + Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" exited with {d} status<r>", .{ std.fs.path.basename(executable), code }); + Global.exit(code); + }, + .Signal => |sig| { + Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" signaled {d}<r>", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, + .Stopped => |sig| { + Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" stopped: {d}<r>", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, + .Unknown => |sig| { + Output.prettyErrorln("<r><red>error<r> \"<b>{s}<r>\" stopped: {d}<r>", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, } return true; |