From a1e786011d955933a10a295089b64b57c328ed33 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 10 Nov 2022 19:50:35 -0800 Subject: [bun run] Fix potential crash when a command terminates abnormally --- src/cli/run_command.zig | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') 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("error: Failed to run \"{s}\" due to error {s}", .{ std.fs.path.basename(executable), @errorName(err) }); Global.exit(1); }; - - if (result.Exited > 0) { - Output.prettyErrorln("error \"{s}\" exited with {d} status", .{ std.fs.path.basename(executable), result.Exited }); - Global.exit(result.Exited); + switch (result) { + .Exited => |code| { + Output.prettyErrorln("error \"{s}\" exited with {d} status", .{ std.fs.path.basename(executable), code }); + Global.exit(code); + }, + .Signal => |sig| { + Output.prettyErrorln("error \"{s}\" signaled {d}", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, + .Stopped => |sig| { + Output.prettyErrorln("error \"{s}\" stopped: {d}", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, + .Unknown => |sig| { + Output.prettyErrorln("error \"{s}\" stopped: {d}", .{ std.fs.path.basename(executable), sig }); + Global.exit(1); + }, } return true; -- cgit v1.2.3