authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-18 21:15:29+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-10-19 18:30:35+01:00
log19c4660c77130e78503e2e7e9e4ad2ec8e0985d6
tree5199e6d6301827ba22d0e18ffb6198711b6a2994
parentc3b8abfc26e5b5e3de79fc4270d4540588541c02
signature Commit is signed but in an unrecognized format.

Maker: fix error handling bugs in `configure`


1 files changed, 52 insertions(+), 10 deletions(-)

lib/compiler/Maker.zig+52-10
......@@ -1101,6 +1101,9 @@ pub fn main(init: process.Init.Minimal) !void {
11011101 if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig compilation failure");
11021102 break :c true;
11031103 },
1104 error.StdoutWriteFailed => {
1105 fatal("failed writing to stdout: {t}", .{stdout_writer_allocation.err.?});
1106 },
11041107 else => |e| w: {
11051108 log.err("configuration failed: {t}", .{e});
11061109 break :w false;
......@@ -1163,7 +1166,14 @@ const ConfigureOptions = struct {
11631166 error_bundle: ?*ErrorBundle = null,
11641167};
11651168
1166fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1169const ConfigureError = Allocator.Error || Io.Cancelable || error{
1170 Unexpected,
1171 AlreadyReported,
1172 FailedButCacheIntact,
1173 StdoutWriteFailed,
1174};
1175
1176fn configure(graph: *Graph, options: ConfigureOptions) ConfigureError!ScannedConfig {
11671177 const configure_argv = options.configure_argv;
11681178 const gpa = graph.cache.gpa;
11691179 const io = graph.io;
......@@ -1328,7 +1338,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
13281338 defer job_queue.deinit();
13291339
13301340 if (options.system_pkg_dir_path == null) {
1331 try http_client.initDefaultProxies(arena, &graph.environ_map);
1341 http_client.initDefaultProxies(arena, &graph.environ_map) catch |err| switch (err) {
1342 error.NameTooLong,
1343 error.InvalidHostName,
1344 error.InvalidPort,
1345 error.InvalidFormat,
1346 error.UnexpectedCharacter,
1347 error.UriMissingHost,
1348 => |e| {
1349 log.err("failed to initialize HTTP client: {t}", .{e});
1350 return error.AlreadyReported;
1351 },
1352 else => |e| return e,
1353 };
13321354 }
13331355
13341356 try job_queue.all_fetches.ensureUnusedCapacity(gpa, 1);
......@@ -1410,10 +1432,10 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
14101432 .writer = initStdoutWriter(io),
14111433 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
14121434 }, arena, graph.global_cache_root, &job_queue, &fetch, &fork_set) catch |err| switch (err) {
1413 error.WriteFailed => return stdout_writer_allocation.err.?,
1435 error.WriteFailed => return error.StdoutWriteFailed,
14141436 else => |e| return e,
14151437 };
1416 try stdout_writer_allocation.flush();
1438 stdout_writer_allocation.flush() catch return error.StdoutWriteFailed;
14171439 process.exit(0);
14181440 }
14191441
......@@ -1444,11 +1466,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
14441466 .root_dir = graph.local_cache_root,
14451467 .sub_path = try arena.print("o/{s}/dependencies.zig", .{&hex_digest}),
14461468 };
1447 var atomic_file = try dependencies_zig_path.root_dir.handle.createFileAtomic(
1469 var atomic_file = dependencies_zig_path.root_dir.handle.createFileAtomic(
14481470 io,
14491471 dependencies_zig_path.sub_path,
14501472 .{ .make_path = true, .replace = true },
1451 );
1473 ) catch |err| switch (err) {
1474 error.Canceled => |e| return e,
1475 else => |e| {
1476 log.err("failed to write {qf}: {t}", .{ dependencies_zig_path, e });
1477 return error.AlreadyReported;
1478 },
1479 };
14521480 defer atomic_file.deinit(io);
14531481 atomic_file.file.writeStreamingAll(io, dependencies_source.items) catch |err|
14541482 fatal("writing dependencies.zig contents: {t}", .{err});
......@@ -1596,11 +1624,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
15961624 .root_dir = graph.local_cache_root,
15971625 .sub_path = try arena.print("tmp" ++ Dir.path.sep_str ++ "{x}", .{randInt(io, u64)}),
15981626 };
1599 const config_tmp_file: Io.File = try config_tmp_path.root_dir.handle.createFile(
1627 const config_tmp_file: Io.File = config_tmp_path.root_dir.handle.createFile(
16001628 io,
16011629 config_tmp_path.sub_path,
16021630 .{ .read = true, .exclusive = true },
1603 );
1631 ) catch |err| switch (err) {
1632 error.Canceled => |e| return e,
1633 else => |e| {
1634 log.err("failed to create {qf}: {t}", .{ config_tmp_path, e });
1635 return error.AlreadyReported;
1636 },
1637 };
16041638 defer config_tmp_file.close(io);
16051639
16061640 const term = term: {
......@@ -1663,11 +1697,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
16631697
16641698 if (config_man) |man| for (configuration.path_deps) |path_dep| {
16651699 const path = try confPathDepToCachePath(arena, graph, &configuration, path_dep);
1666 try man.addDiscoveredPath(.{
1700 var diag: Cache.Manifest.AddDiscoveredPathDiagnostic = undefined;
1701 man.addDiscoveredPath(.{
16671702 .discovered_path = .{ .unresolved = path },
16681703 .handle = if (path_dep.flags.is_directory) .{ .dir = null } else .{ .file = null },
16691704 .metadata_only = path_dep.flags.metadata_only,
1670 });
1705 .diagnostic = &diag,
1706 }) catch |err| switch (err) {
1707 error.FileSystemFailure => {
1708 log.err("failed to register dependency on {qf}: {f}", .{ path, diag });
1709 return error.AlreadyReported;
1710 },
1711 else => |e| return e,
1712 };
16711713 };
16721714
16731715 // If it is poisoned, there is no point in moving it to cached