diff --git a/lib/compiler/Maker.zig b/lib/compiler/Maker.zig index 66ba521c040d736e679af5bf58773bfcecfc55d2..607132eaeaed88a5b115e3783cfa918969873b65 100644 --- a/lib/compiler/Maker.zig +++ b/lib/compiler/Maker.zig @@ -1101,6 +1101,9 @@ pub fn main(init: process.Init.Minimal) !void { if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig compilation failure"); break :c true; }, + error.StdoutWriteFailed => { + fatal("failed writing to stdout: {t}", .{stdout_writer_allocation.err.?}); + }, else => |e| w: { log.err("configuration failed: {t}", .{e}); break :w false; @@ -1163,7 +1166,14 @@ const ConfigureOptions = struct { error_bundle: ?*ErrorBundle = null, }; -fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { +const ConfigureError = Allocator.Error || Io.Cancelable || error{ + Unexpected, + AlreadyReported, + FailedButCacheIntact, + StdoutWriteFailed, +}; + +fn configure(graph: *Graph, options: ConfigureOptions) ConfigureError!ScannedConfig { const configure_argv = options.configure_argv; const gpa = graph.cache.gpa; const io = graph.io; @@ -1328,7 +1338,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { defer job_queue.deinit(); if (options.system_pkg_dir_path == null) { - try http_client.initDefaultProxies(arena, &graph.environ_map); + http_client.initDefaultProxies(arena, &graph.environ_map) catch |err| switch (err) { + error.NameTooLong, + error.InvalidHostName, + error.InvalidPort, + error.InvalidFormat, + error.UnexpectedCharacter, + error.UriMissingHost, + => |e| { + log.err("failed to initialize HTTP client: {t}", .{e}); + return error.AlreadyReported; + }, + else => |e| return e, + }; } try job_queue.all_fetches.ensureUnusedCapacity(gpa, 1); @@ -1410,10 +1432,10 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { .writer = initStdoutWriter(io), .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE), }, arena, graph.global_cache_root, &job_queue, &fetch, &fork_set) catch |err| switch (err) { - error.WriteFailed => return stdout_writer_allocation.err.?, + error.WriteFailed => return error.StdoutWriteFailed, else => |e| return e, }; - try stdout_writer_allocation.flush(); + stdout_writer_allocation.flush() catch return error.StdoutWriteFailed; process.exit(0); } @@ -1444,11 +1466,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { .root_dir = graph.local_cache_root, .sub_path = try arena.print("o/{s}/dependencies.zig", .{&hex_digest}), }; - var atomic_file = try dependencies_zig_path.root_dir.handle.createFileAtomic( + var atomic_file = dependencies_zig_path.root_dir.handle.createFileAtomic( io, dependencies_zig_path.sub_path, .{ .make_path = true, .replace = true }, - ); + ) catch |err| switch (err) { + error.Canceled => |e| return e, + else => |e| { + log.err("failed to write {qf}: {t}", .{ dependencies_zig_path, e }); + return error.AlreadyReported; + }, + }; defer atomic_file.deinit(io); atomic_file.file.writeStreamingAll(io, dependencies_source.items) catch |err| fatal("writing dependencies.zig contents: {t}", .{err}); @@ -1596,11 +1624,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { .root_dir = graph.local_cache_root, .sub_path = try arena.print("tmp" ++ Dir.path.sep_str ++ "{x}", .{randInt(io, u64)}), }; - const config_tmp_file: Io.File = try config_tmp_path.root_dir.handle.createFile( + const config_tmp_file: Io.File = config_tmp_path.root_dir.handle.createFile( io, config_tmp_path.sub_path, .{ .read = true, .exclusive = true }, - ); + ) catch |err| switch (err) { + error.Canceled => |e| return e, + else => |e| { + log.err("failed to create {qf}: {t}", .{ config_tmp_path, e }); + return error.AlreadyReported; + }, + }; defer config_tmp_file.close(io); const term = term: { @@ -1663,11 +1697,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { if (config_man) |man| for (configuration.path_deps) |path_dep| { const path = try confPathDepToCachePath(arena, graph, &configuration, path_dep); - try man.addDiscoveredPath(.{ + var diag: Cache.Manifest.AddDiscoveredPathDiagnostic = undefined; + man.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = path }, .handle = if (path_dep.flags.is_directory) .{ .dir = null } else .{ .file = null }, .metadata_only = path_dep.flags.metadata_only, - }); + .diagnostic = &diag, + }) catch |err| switch (err) { + error.FileSystemFailure => { + log.err("failed to register dependency on {qf}: {f}", .{ path, diag }); + return error.AlreadyReported; + }, + else => |e| return e, + }; }; // If it is poisoned, there is no point in moving it to cached