From ffd8df87eebb7dbb8ee52bc9e23f573329bc6477 Mon Sep 17 00:00:00 2001 From: Istvan Szekeres Date: Thu, 18 Jul 2024 08:27:58 +0100 Subject: [PATCH] Better error message if can't execute program Without this in case poop can't exec the target the error message is not very helpful, not telling which command failed and produces a stack trace that doesn't help figuring out the issue: ``` error: AccessDenied /usr/lib/zig/lib/std/process/Child.zig:423:5: 0x104ad77 in waitPosix (poop) return self.term.?; ^ /usr/lib/zig/lib/std/process/Child.zig:300:9: 0x104adf3 in wait (poop) try self.waitPosix(); ^ /home/user/poop/src/main.zig:243:26: 0x105222a in main (poop) const term = try child.wait(); ``` This changes the output to something more useful: ``` error: Couldn't execute /etc: AccessDenied ``` --- src/main.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 64b02fc..2be313d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -244,7 +244,10 @@ pub fn main() !void { } } - const term = try child.wait(); + const term = child.wait() catch |err| { + std.debug.print("\nerror: Couldn't execute {s}: {s}\n", .{ command.argv[0], @errorName(err) }); + std.process.exit(1); + }; const end = timer.read(); _ = std.os.linux.ioctl(perf_fds[0], PERF.EVENT_IOC.DISABLE, PERF.IOC_FLAG_GROUP); const peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;