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 {...@@ -1101,6 +1101,9 @@ pub fn main(init: process.Init.Minimal) !void {
1101 if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig compilation failure");1101 if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig compilation failure");
1102 break :c true;1102 break :c true;
1103 },1103 },
1104 error.StdoutWriteFailed => {
1105 fatal("failed writing to stdout: {t}", .{stdout_writer_allocation.err.?});
1106 },
1104 else => |e| w: {1107 else => |e| w: {
1105 log.err("configuration failed: {t}", .{e});1108 log.err("configuration failed: {t}", .{e});
1106 break :w false;1109 break :w false;
...@@ -1163,7 +1166,14 @@ const ConfigureOptions = struct {...@@ -1163,7 +1166,14 @@ const ConfigureOptions = struct {
1163 error_bundle: ?*ErrorBundle = null,1166 error_bundle: ?*ErrorBundle = null,
1164};1167};
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 {
1167 const configure_argv = options.configure_argv;1177 const configure_argv = options.configure_argv;
1168 const gpa = graph.cache.gpa;1178 const gpa = graph.cache.gpa;
1169 const io = graph.io;1179 const io = graph.io;
...@@ -1328,7 +1338,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1328,7 +1338,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1328 defer job_queue.deinit();1338 defer job_queue.deinit();
13291339
1330 if (options.system_pkg_dir_path == null) {1340 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 };
1332 }1354 }
13331355
1334 try job_queue.all_fetches.ensureUnusedCapacity(gpa, 1);1356 try job_queue.all_fetches.ensureUnusedCapacity(gpa, 1);
...@@ -1410,10 +1432,10 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1410,10 +1432,10 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1410 .writer = initStdoutWriter(io),1432 .writer = initStdoutWriter(io),
1411 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),1433 .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE),
1412 }, arena, graph.global_cache_root, &job_queue, &fetch, &fork_set) catch |err| switch (err) {1434 }, 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,
1414 else => |e| return e,1436 else => |e| return e,
1415 };1437 };
1416 try stdout_writer_allocation.flush();1438 stdout_writer_allocation.flush() catch return error.StdoutWriteFailed;
1417 process.exit(0);1439 process.exit(0);
1418 }1440 }
14191441
...@@ -1444,11 +1466,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1444,11 +1466,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1444 .root_dir = graph.local_cache_root,1466 .root_dir = graph.local_cache_root,
1445 .sub_path = try arena.print("o/{s}/dependencies.zig", .{&hex_digest}),1467 .sub_path = try arena.print("o/{s}/dependencies.zig", .{&hex_digest}),
1446 };1468 };
1447 var atomic_file = try dependencies_zig_path.root_dir.handle.createFileAtomic(1469 var atomic_file = dependencies_zig_path.root_dir.handle.createFileAtomic(
1448 io,1470 io,
1449 dependencies_zig_path.sub_path,1471 dependencies_zig_path.sub_path,
1450 .{ .make_path = true, .replace = true },1472 .{ .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 };
1452 defer atomic_file.deinit(io);1480 defer atomic_file.deinit(io);
1453 atomic_file.file.writeStreamingAll(io, dependencies_source.items) catch |err|1481 atomic_file.file.writeStreamingAll(io, dependencies_source.items) catch |err|
1454 fatal("writing dependencies.zig contents: {t}", .{err});1482 fatal("writing dependencies.zig contents: {t}", .{err});
...@@ -1596,11 +1624,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1596,11 +1624,17 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
1596 .root_dir = graph.local_cache_root,1624 .root_dir = graph.local_cache_root,
1597 .sub_path = try arena.print("tmp" ++ Dir.path.sep_str ++ "{x}", .{randInt(io, u64)}),1625 .sub_path = try arena.print("tmp" ++ Dir.path.sep_str ++ "{x}", .{randInt(io, u64)}),
1598 };1626 };
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(
1600 io,1628 io,
1601 config_tmp_path.sub_path,1629 config_tmp_path.sub_path,
1602 .{ .read = true, .exclusive = true },1630 .{ .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 };
1604 defer config_tmp_file.close(io);1638 defer config_tmp_file.close(io);
16051639
1606 const term = term: {1640 const term = term: {
...@@ -1663,11 +1697,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {...@@ -1663,11 +1697,19 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig {
16631697
1664 if (config_man) |man| for (configuration.path_deps) |path_dep| {1698 if (config_man) |man| for (configuration.path_deps) |path_dep| {
1665 const path = try confPathDepToCachePath(arena, graph, &configuration, path_dep);1699 const path = try confPathDepToCachePath(arena, graph, &configuration, path_dep);
1666 try man.addDiscoveredPath(.{1700 var diag: Cache.Manifest.AddDiscoveredPathDiagnostic = undefined;
1701 man.addDiscoveredPath(.{
1667 .discovered_path = .{ .unresolved = path },1702 .discovered_path = .{ .unresolved = path },
1668 .handle = if (path_dep.flags.is_directory) .{ .dir = null } else .{ .file = null },1703 .handle = if (path_dep.flags.is_directory) .{ .dir = null } else .{ .file = null },
1669 .metadata_only = path_dep.flags.metadata_only,1704 .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 };
1671 };1713 };
16721714
1673 // If it is poisoned, there is no point in moving it to cached1715 // If it is poisoned, there is no point in moving it to cached