authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-05 00:41:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-05 00:41:17-07:00
logf4c6e5d94e1d06a2b438632de0808947f6561798
treea22ec03efb7f2a5cb111f11bb4f14984778cc951
parentff534d22676b8a934acf1931f91d70c554a4bdca

CLI: better error message for bad input path

Previously it just said `error: NotDir` but now it says `error: unable to open '<path>': NotDir`.

1 files changed, 9 insertions(+), 2 deletions(-)

src/main.zig+9-2
...@@ -2763,7 +2763,14 @@ fn buildOutputType(...@@ -2763,7 +2763,14 @@ fn buildOutputType(
2763 defer gpa.free(rel_src_path);2763 defer gpa.free(rel_src_path);
2764 break :blk try Package.create(gpa, p, rel_src_path);2764 break :blk try Package.create(gpa, p, rel_src_path);
2765 } else {2765 } else {
2766 break :blk try Package.create(gpa, fs.path.dirname(src_path), fs.path.basename(src_path));2766 const root_src_dir_path = fs.path.dirname(src_path);
2767 break :blk Package.create(gpa, root_src_dir_path, fs.path.basename(src_path)) catch |err| {
2768 if (root_src_dir_path) |p| {
2769 fatal("unable to open '{s}': {s}", .{ p, @errorName(err) });
2770 } else {
2771 return err;
2772 }
2773 };
2767 }2774 }
2768 } else null;2775 } else null;
2769 defer if (main_pkg) |p| p.destroy(gpa);2776 defer if (main_pkg) |p| p.destroy(gpa);
...@@ -2792,7 +2799,7 @@ fn buildOutputType(...@@ -2792,7 +2799,7 @@ fn buildOutputType(
2792 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{2799 var zig_lib_directory: Compilation.Directory = if (override_lib_dir) |lib_dir| .{
2793 .path = lib_dir,2800 .path = lib_dir,
2794 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {2801 .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| {
2795 fatal("unable to open zig lib directory from 'zig-lib-dir' argument or env, '{s}': {s}", .{ lib_dir, @errorName(err) });2802 fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) });
2796 },2803 },
2797 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {2804 } else introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
2798 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});2805 fatal("unable to find zig installation directory: {s}\n", .{@errorName(err)});