authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:51:39 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:51:39 -07:00
log1cbf74a6e96c0591c8979ef0eabf714bdaa6eefd
treed4f157cc731fcd5442f8deead6d8ff3227e295a0
parent94d2ad2f7b187287101947911442d9126927c904

add u.fail for explicit noreturn assert and exit


9 files changed, 18 insertions(+), 19 deletions(-)

src/cmd/aq.zig+1-1
......@@ -39,7 +39,7 @@ pub fn execute(args: [][]u8) !void {
3939 return;
4040 }
4141 }
42 u.assert(false, "unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});
42 u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});
4343}
4444
4545pub fn server_fetch(url: []const u8) !json.Value {
src/cmd/fetch.zig+1-1
......@@ -322,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d
322322 }
323323 }
324324 if (notdone.items.len == len) {
325 u.assert(false, "notdone still has {d} items", .{len});
325 u.fail("notdone still has {d} items", .{len});
326326 }
327327 len = notdone.items.len;
328328 }
src/cmd/init.zig+1-2
......@@ -31,8 +31,7 @@ pub fn execute(args: [][]u8) !void {
3131
3232 const name = try inquirer.forString(stdout, stdin, "package name:", gpa, u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) {
3333 error.NoBuildZig => {
34 u.assert(false, "init requires a build.zig file", .{});
35 unreachable;
34 u.fail("init requires a build.zig file", .{});
3635 },
3736 else => return err,
3837 });
src/cmd/zpm.zig+1-1
......@@ -50,7 +50,7 @@ pub fn execute(args: [][]u8) !void {
5050 return;
5151 }
5252 }
53 u.assert(false, "unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});
53 u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});
5454}
5555
5656pub fn server_fetch(url: []const u8) !json.Value {
src/cmd/zpm/add.zig+1-2
......@@ -28,8 +28,7 @@ pub fn execute(args: [][]u8) !void {
2828 break :blk pkg;
2929 }
3030 }
31 u.assert(false, "no package with name '{s}' found", .{args[0]});
32 unreachable;
31 u.fail("no package with name '{s}' found", .{args[0]});
3332 };
3433
3534 u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{});
src/common.zig+5-7
......@@ -127,8 +127,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![
127127 error.IterEmpty => unreachable,
128128 error.NoMemberFound => {
129129 const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?];
130 u.assert(false, "fetch: git: version type '{s}' is invalid.", .{vtype});
131 unreachable;
130 u.fail("fetch: git: version type '{s}' is invalid.", .{vtype});
132131 },
133132 };
134133 if (try u.does_folder_exist(pv)) {
......@@ -141,7 +140,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![
141140 }
142141 try d.type.pull(d.path, pv);
143142 if ((try u.run_cmd(pv, &.{ "git", "checkout", vers.string })) > 0) {
144 u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
143 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
145144 }
146145 if (builtin.os.tag != .windows and vers.id != .branch) {
147146 const pvd = try std.fs.cwd().openDir(pv, .{});
......@@ -184,7 +183,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![
184183 return pv;
185184 }
186185 try std.fs.cwd().deleteTree(pv);
187 u.assert(false, "{s} does not match hash {s}", .{ d.path, d.version });
186 u.fail("{s} does not match hash {s}", .{ d.path, d.version });
188187 return p;
189188 }
190189 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
253252 if (mod_from.is_for_this()) return mod_from;
254253 return null;
255254 }
256 u.assert(false, "no zig.mod found and no override props defined. unable to use add this dependency!", .{});
257 unreachable;
255 u.fail("no zig.mod found and no override props defined. unable to use add this dependency!", .{});
258256 },
259257 else => e,
260258 };
......@@ -390,7 +388,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
390388 });
391389 },
392390 else => {
393 u.assert(false, "invalid zigmod.lock version: {d}", .{v});
391 u.fail("invalid zigmod.lock version: {d}", .{v});
394392 },
395393 }
396394 }
src/main.zig+1-2
......@@ -63,8 +63,7 @@ pub fn main() !void {
6363 const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) {
6464 else => return e,
6565 error.FileNotFound => {
66 u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]});
67 unreachable;
66 u.fail("unknown command \"{s}\" for \"zigmod\"", .{args[0]});
6867 },
6968 };
7069 try std.io.getStdOut().writeAll(result.stdout);
src/util/funcs.zig+6-2
......@@ -25,6 +25,11 @@ pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {
2525 }
2626}
2727
28pub fn fail(comptime fmt: []const u8, args: anytype) noreturn {
29 assert(false, fmt, args);
30 unreachable;
31}
32
2833pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {
2934 if (array.len <= n) {
3035 return def;
......@@ -160,8 +165,7 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {
160165pub fn run_cmd_raw(dir: ?[]const u8, args: []const []const u8) !std.ChildProcess.ExecResult {
161166 return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
162167 error.FileNotFound => {
163 u.assert(false, "\"{s}\" command not found", .{args[0]});
164 unreachable;
168 u.fail("\"{s}\" command not found", .{args[0]});
165169 },
166170 else => return e,
167171 };
src/util/modfile.zig+1-1
......@@ -48,7 +48,7 @@ pub const ModFile = struct {
4848 const main = mapping.get_string("main");
4949
5050 if (std.mem.indexOf(u8, name, "/")) |_| {
51 u.assert(false, "name may not contain any '/'", .{});
51 u.fail("name may not contain any '/'", .{});
5252 }
5353
5454 return Self{