diff --git a/src/cmd_init.zig b/src/cmd_init.zig index a4061e50e765c9b8833a20029059667bab18f2a1..d8a1f9d98aedaf41977c85d3e5c400fa18126768 100644 --- a/src/cmd_init.zig +++ b/src/cmd_init.zig @@ -35,12 +35,12 @@ fn detect_pkgname(def: []const u8) ![]const u8 { fn detct_mainfile(def: []const u8) ![]const u8 { if (def.len > 0) { - if (u.does_file_exist(def)) { + if (try u.does_file_exist(def)) { if (std.mem.endsWith(u8, def, ".zig")) { return def; } } } - std.debug.assert(u.does_file_exist("./src/main.zig")); + std.debug.assert(try u.does_file_exist("./src/main.zig")); return "src/main.zig"; } diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 05d82bff573d2913dde7a1359229674e9b394819..118543164d75eae76a6a60e9072166c8756a8d38 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -40,11 +40,11 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 { return in; } -pub fn does_file_exist(fpath: []const u8) bool { - const abs_path = std.fs.realpathAlloc(gpa, fpath) catch unreachable; +pub fn does_file_exist(fpath: []const u8) !bool { + const abs_path = try std.fs.realpathAlloc(gpa, fpath); const file = std.fs.openFileAbsolute(abs_path, .{}) catch |e| switch (e) { error.FileNotFound => return false, - else => unreachable, + else => return e, }; file.close(); return true;