diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-28 21:48:56 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-28 21:49:40 -0700 |
| commit | e0a78d10ccb3c9b5d6ebb17f32ef3b79363cd4d0 (patch) | |
| tree | 782264e99a163c7ffe8e289ddf93803dd7377209 | |
| parent | 78dcd1b23ed4ca9d4202e1613ce2ec17c7b85e5c (diff) | |
| download | zig-e0a78d10ccb3c9b5d6ebb17f32ef3b79363cd4d0.tar.gz zig-e0a78d10ccb3c9b5d6ebb17f32ef3b79363cd4d0.zip | |
stage2: better error message for root zig source file not found
closes #6777
closes #6893
| -rw-r--r-- | src/Cache.zig | 20 | ||||
| -rw-r--r-- | src/Compilation.zig | 9 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/Cache.zig b/src/Cache.zig index 7d77782a6f..3d33226f27 100644 --- a/src/Cache.zig +++ b/src/Cache.zig @@ -194,6 +194,9 @@ pub const Manifest = struct { files: std.ArrayListUnmanaged(File) = .{}, hex_digest: [hex_digest_len]u8, debug_bin_digest: DebugBinDigest = null_debug_bin_digest, + /// Populated when hit() returns an error because of one + /// of the files listed in the manifest. + failed_file_index: ?usize = null, /// Add a file as a dependency of process being cached. When `hit` is /// called, the file's contents will be checked to ensure that it matches @@ -255,6 +258,8 @@ pub const Manifest = struct { pub fn hit(self: *Manifest) !bool { assert(self.manifest_file == null); + self.failed_file_index = null; + const ext = ".txt"; var manifest_file_path: [self.hex_digest.len + ext.len]u8 = undefined; @@ -366,7 +371,10 @@ pub const Manifest = struct { }; defer this_file.close(); - const actual_stat = try this_file.stat(); + const actual_stat = this_file.stat() catch |err| { + self.failed_file_index = idx; + return err; + }; const size_match = actual_stat.size == cache_hash_file.stat.size; const mtime_match = actual_stat.mtime == cache_hash_file.stat.mtime; const inode_match = actual_stat.inode == cache_hash_file.stat.inode; @@ -382,7 +390,10 @@ pub const Manifest = struct { } var actual_digest: BinDigest = undefined; - try hashFile(this_file, &actual_digest); + hashFile(this_file, &actual_digest) catch |err| { + self.failed_file_index = idx; + return err; + }; if (!mem.eql(u8, &cache_hash_file.bin_digest, &actual_digest)) { cache_hash_file.bin_digest = actual_digest; @@ -407,7 +418,10 @@ pub const Manifest = struct { self.manifest_dirty = true; while (idx < input_file_count) : (idx += 1) { const ch_file = &self.files.items[idx]; - try self.populateFileHash(ch_file); + self.populateFileHash(ch_file) catch |err| { + self.failed_file_index = idx; + return err; + }; } return false; } diff --git a/src/Compilation.zig b/src/Compilation.zig index 39dd97c3a2..8a0a6ee58d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1629,7 +1629,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor unreachable; self.updateStage1Module(main_progress_node) catch |err| { - fatal("unable to build stage1 zig object: {}", .{@errorName(err)}); + fatal("unable to build stage1 zig object: {s}", .{@errorName(err)}); }; }, }; @@ -3001,7 +3001,12 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node const prev_hash_state = man.hash.peekBin(); const input_file_count = man.files.items.len; - if (try man.hit()) { + const hit = man.hit() catch |err| { + const i = man.failed_file_index orelse return err; + const file_path = man.files.items[i].path orelse return err; + fatal("unable to build stage1 zig object: {s}: {s}", .{ @errorName(err), file_path }); + }; + if (hit) { const digest = man.final(); // We use an extra hex-encoded byte here to store some flags. |
