diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-06-11 02:25:33 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-06-12 17:51:30 +0100 |
| commit | 1b27369acbb2009935d49c6906363e8fa425313a (patch) | |
| tree | 2bc46951ce1e168c22ff21ac39cf4af849bd605b /src/main.zig | |
| parent | 7f2f107a1ed451c94da0db6ff559bfee3ce512a5 (diff) | |
| download | zig-1b27369acbb2009935d49c6906363e8fa425313a.tar.gz zig-1b27369acbb2009935d49c6906363e8fa425313a.zip | |
cli: correctly error for missing output directories
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig index dc1d66381b..3821fafb80 100644 --- a/src/main.zig +++ b/src/main.zig @@ -712,7 +712,16 @@ const Emit = union(enum) { .{ @tagName(reason), path }, ), } - } else .{ .yes_path = path }, + } else e: { + // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would. + if (fs.path.dirname(path)) |dir_path| { + var dir = fs.cwd().openDir(dir_path, .{}) catch |err| { + fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) }); + }; + dir.close(); + } + break :e .{ .yes_path = path }; + }, }; } }; @@ -3220,7 +3229,16 @@ fn buildOutputType( .yes => |path| if (output_to_cache != null) { assert(output_to_cache == .listen); // there was an explicit bin path fatal("--listen incompatible with explicit output path '{s}'", .{path}); - } else .{ .yes_path = path }, + } else emit: { + // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would. + if (fs.path.dirname(path)) |dir_path| { + var dir = fs.cwd().openDir(dir_path, .{}) catch |err| { + fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) }); + }; + dir.close(); + } + break :emit .{ .yes_path = path }; + }, .yes_a_out => emit: { assert(output_to_cache == null); break :emit .{ .yes_path = switch (target.ofmt) { |
