@@ -712,7 +712,16 @@ const Emit = union(enum) {
712
712
.{ @tagName (reason ), path },
713
713
),
714
714
}
715
- } else .{ .yes_path = path },
715
+ } else e : {
716
+ // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
717
+ if (fs .path .dirname (path )) | dir_path | {
718
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | {
719
+ fatal ("unable to open output directory '{s}': {s}" , .{ dir_path , @errorName (err ) });
720
+ };
721
+ dir .close ();
722
+ }
723
+ break :e .{ .yes_path = path };
724
+ },
716
725
};
717
726
}
718
727
};
@@ -3220,7 +3229,16 @@ fn buildOutputType(
3220
3229
.yes = > | path | if (output_to_cache != null ) {
3221
3230
assert (output_to_cache == .listen ); // there was an explicit bin path
3222
3231
fatal ("--listen incompatible with explicit output path '{s}'" , .{path });
3223
- } else .{ .yes_path = path },
3232
+ } else emit : {
3233
+ // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
3234
+ if (fs .path .dirname (path )) | dir_path | {
3235
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | {
3236
+ fatal ("unable to open output directory '{s}': {s}" , .{ dir_path , @errorName (err ) });
3237
+ };
3238
+ dir .close ();
3239
+ }
3240
+ break :emit .{ .yes_path = path };
3241
+ },
3224
3242
.yes_a_out = > emit : {
3225
3243
assert (output_to_cache == null );
3226
3244
break :emit .{ .yes_path = switch (target .ofmt ) {
0 commit comments