Improve Cache Unavailable error message due to file permissions issue
Zig Version
0.14.0-dev.66+1fdf13a14
Steps to Reproduce and Observed Output
run zig build test
modify a file to trigger cache miss
run sudo /path/to/zig/executable build test
modify a file to trigger cache miss
run zig build test
observe cache unavailable error
test
└─ run test
└─ zig test Debug native failure
error: error: CacheUnavailable
Remedy the situation by deleting the .zig-cache/ directory
Context: I was writing a quick test to test some interactions with network interfaces which required elevated privileges. I realize that it is a poor test design if it requires elevated privileges.
Expected Output
Perhaps this could report a file permissions error instead?
Adding the following line leads to an AccessDenied error rather than CacheUnavailable for this situation. I'm happy to open up a PR, but I'm not certain where/ how a test could be written to cover this behavior.
diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig
index fe2a6b0a83..172f3dfd8e 100644
--- a/lib/std/Build/Cache.zig
+++ b/lib/std/Build/Cache.zig
@@ -568,6 +568,7 @@ pub const Manifest = struct {
if (try self.upgradeToExclusiveLock()) continue;
return false;
},
+ error.AccessDenied => return error.AccessDenied,
else => return error.CacheUnavailable,
};
defer this_file.close();