diff --git a/src/common.zig b/src/common.zig index 1db76125a30c063975aff3f8c2501470bd73cf40..dade73e86e632779928917b6d85cf62779c34cc1 100644 --- a/src/common.zig +++ b/src/common.zig @@ -179,7 +179,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! if (try extras.doesFolderExist(null, pv)) { return pv; } - const file_name = try u.last(try u.split(options.alloc, d.path, "/")); + const file_name = u.last(try u.split(options.alloc, d.path, "/")).?; if (d.version.len > 0) { if (try extras.doesFolderExist(null, pv)) { return pv; diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 54f8d91a3a9372d5ed1ab585a0d0eb6692845e2a..e35a7c9db2a14fb5d3942155b7369661f2ac19b0 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -79,10 +79,8 @@ pub fn list_remove(alloc: std.mem.Allocator, input: []string, search: string) ![ return list.toOwnedSlice(); } -pub fn last(in: []string) !string { - if (in.len == 0) { - return error.EmptyArray; - } +pub fn last(in: []string) ?string { + if (in.len == 0) return null; return in[in.len - 1]; }