Skip to content

Commit

Permalink
cli: print actual error when cannot open input file
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Sep 16, 2024
1 parent d6a8b3b commit 1909ef2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ pub fn main() !void {
}

const fname = filename orelse fatal("no input file specified", .{});
const file = try std.fs.cwd().openFile(fname, .{});
const file = std.fs.cwd().openFile(fname, .{}) catch |err| switch (err) {
error.FileNotFound => fatal("file not found: {s}", .{fname}),
else => |e| fatal("unexpected error occurred: {s}", .{@errorName(e)}),
};
defer file.close();
const data = try file.readToEndAlloc(arena, std.math.maxInt(u32));

Expand Down

0 comments on commit 1909ef2

Please sign in to comment.