From f82d7e87a3c640f55714c92c5606d84c13311d78 Mon Sep 17 00:00:00 2001 From: achan1989 Date: Thu, 30 Jan 2025 13:10:17 +0000 Subject: [PATCH] main: better error message if the global cache dir is unusable Fixes #19400 --- src/main.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 34d610bdd1..a925286c7e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5002,8 +5002,16 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var global_cache_directory: Directory = l: { const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena); + const dir = fs.cwd().makeOpenPath(p, .{}) catch |err| { + const base_msg = "unable to open or create the global Zig cache at '{s}': {s}.{s}"; + const extra = "\nIf this location is not writable then consider specifying an " ++ + "alternative with the ZIG_GLOBAL_CACHE_DIR environment variable or the " ++ + "--global-cache-dir option."; + const show_extra = err == error.AccessDenied or err == error.ReadOnlyFileSystem; + fatal(base_msg, .{ p, @errorName(err), if (show_extra) extra else "" }); + }; break :l .{ - .handle = try fs.cwd().makeOpenPath(p, .{}), + .handle = dir, .path = p, }; };