diff --git a/src/cmd/aq.zig b/src/cmd/aq.zig index 0e823257d3bb7d9838c0f3beaab6ebda772abeb2..9b164cd48b6ceeb948ab304f60fe9ec875a097a6 100644 --- a/src/cmd/aq.zig +++ b/src/cmd/aq.zig @@ -39,7 +39,7 @@ pub fn execute(args: [][]u8) !void { return; } } - u.assert(false, "unknown command \"{s}\" for \"zigmod aq\"", .{args[0]}); + u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]}); } pub fn server_fetch(url: []const u8) !json.Value { diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index c1f9b50886f0b99a7fc31e4e4a4158a060856456..e62c0b62268f426fead304f4666847c326663726 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -322,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d } } if (notdone.items.len == len) { - u.assert(false, "notdone still has {d} items", .{len}); + u.fail("notdone still has {d} items", .{len}); } len = notdone.items.len; } diff --git a/src/cmd/init.zig b/src/cmd/init.zig index 03fde7b8467fc99dd265457d36ce6b91e8e2b391..32b49b356fc2dc597ffc640c93b3c297f3a4d502 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -31,8 +31,7 @@ pub fn execute(args: [][]u8) !void { const name = try inquirer.forString(stdout, stdin, "package name:", gpa, u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) { error.NoBuildZig => { - u.assert(false, "init requires a build.zig file", .{}); - unreachable; + u.fail("init requires a build.zig file", .{}); }, else => return err, }); diff --git a/src/cmd/zpm.zig b/src/cmd/zpm.zig index b3329aadc45432d502d3506b906e206ae7a7c4aa..13b6f0ac6b3536e659222aa324f970217c964326 100644 --- a/src/cmd/zpm.zig +++ b/src/cmd/zpm.zig @@ -50,7 +50,7 @@ pub fn execute(args: [][]u8) !void { return; } } - u.assert(false, "unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]}); + u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]}); } pub fn server_fetch(url: []const u8) !json.Value { diff --git a/src/cmd/zpm/add.zig b/src/cmd/zpm/add.zig index 7a9611bb8f12de4518df602db44525fbc485514b..5fdd7600b2e2934321b062ef65a69e0dadfadbb0 100644 --- a/src/cmd/zpm/add.zig +++ b/src/cmd/zpm/add.zig @@ -28,8 +28,7 @@ pub fn execute(args: [][]u8) !void { break :blk pkg; } } - u.assert(false, "no package with name '{s}' found", .{args[0]}); - unreachable; + u.fail("no package with name '{s}' found", .{args[0]}); }; u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{}); diff --git a/src/common.zig b/src/common.zig index 1581daf4a352e981b1b6b32bc65ba087f38481fc..51cce6cbc44f6ca09f0980009fb76c1b191999b7 100644 --- a/src/common.zig +++ b/src/common.zig @@ -127,8 +127,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![ error.IterEmpty => unreachable, error.NoMemberFound => { const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?]; - u.assert(false, "fetch: git: version type '{s}' is invalid.", .{vtype}); - unreachable; + u.fail("fetch: git: version type '{s}' is invalid.", .{vtype}); }, }; if (try u.does_folder_exist(pv)) { @@ -141,7 +140,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![ } try d.type.pull(d.path, pv); if ((try u.run_cmd(pv, &.{ "git", "checkout", vers.string })) > 0) { - u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string }); + u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string }); } if (builtin.os.tag != .windows and vers.id != .branch) { const pvd = try std.fs.cwd().openDir(pv, .{}); @@ -184,7 +183,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![ return pv; } try std.fs.cwd().deleteTree(pv); - u.assert(false, "{s} does not match hash {s}", .{ d.path, d.version }); + u.fail("{s} does not match hash {s}", .{ d.path, d.version }); return p; } if (try u.does_folder_exist(p)) { @@ -253,8 +252,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOp if (mod_from.is_for_this()) return mod_from; return null; } - u.assert(false, "no zig.mod found and no override props defined. unable to use add this dependency!", .{}); - unreachable; + u.fail("no zig.mod found and no override props defined. unable to use add this dependency!", .{}); }, else => e, }; @@ -390,7 +388,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 { }); }, else => { - u.assert(false, "invalid zigmod.lock version: {d}", .{v}); + u.fail("invalid zigmod.lock version: {d}", .{v}); }, } } diff --git a/src/main.zig b/src/main.zig index 6d7dd2cdff24ab5eb1fc3a614f852b3aaf207c8e..4ff923a7e7a8bf436c077f4b936c82f58e646724 100644 --- a/src/main.zig +++ b/src/main.zig @@ -63,8 +63,7 @@ pub fn main() !void { const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) { else => return e, error.FileNotFound => { - u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]}); - unreachable; + u.fail("unknown command \"{s}\" for \"zigmod\"", .{args[0]}); }, }; try std.io.getStdOut().writeAll(result.stdout); diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 86c677ced3cabb75fec54c1d716dc0253879e12c..9f3c9be1ce2cb4b456e14df6b47f58fd3ec6e713 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -25,6 +25,11 @@ pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void { } } +pub fn fail(comptime fmt: []const u8, args: anytype) noreturn { + assert(false, fmt, args); + unreachable; +} + pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T { if (array.len <= n) { return def; @@ -160,8 +165,7 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void { pub fn run_cmd_raw(dir: ?[]const u8, args: []const []const u8) !std.ChildProcess.ExecResult { return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { error.FileNotFound => { - u.assert(false, "\"{s}\" command not found", .{args[0]}); - unreachable; + u.fail("\"{s}\" command not found", .{args[0]}); }, else => return e, }; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index b07fb6e8b6f7966f6263c24623167390f04ecb64..f9b5f314c63f902c70189bbf1309205e8cf40e9d 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -48,7 +48,7 @@ pub const ModFile = struct { const main = mapping.get_string("main"); if (std.mem.indexOf(u8, name, "/")) |_| { - u.assert(false, "name may not contain any '/'", .{}); + u.fail("name may not contain any '/'", .{}); } return Self{