authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-19 15:42:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:35-07:00
logf414370fba47e375cc240f3fcaa8fa36c7c0fed3
treef4c9f1df43ae916c0af6efb7a3e00d9514a92142
parent58f8dcd15e04a02185f4e18dbf76c54942e05350

docgen: better error message on failure to read output


1 files changed, 16 insertions(+), 5 deletions(-)

tools/docgen.zig+16-5
......@@ -3,6 +3,7 @@ const builtin = @import("builtin");
33const std = @import("std");
44const Io = std.Io;
55const Dir = std.Io.Dir;
6const Path = std.Build.Cache.Path;
67const process = std.process;
78const Progress = std.Progress;
89const print = std.debug.print;
......@@ -73,8 +74,13 @@ pub fn main(init: std.process.Init) !void {
7374 var out_file_buffer: [4096]u8 = undefined;
7475 var out_file_writer = out_file.writer(io, &out_file_buffer);
7576
76 var code_dir = try Dir.cwd().openDir(io, code_dir_path, .{});
77 defer code_dir.close(io);
77 var code_dir: Path = .{
78 .root_dir = .{
79 .handle = try Dir.cwd().openDir(io, code_dir_path, .{}),
80 .path = code_dir_path,
81 },
82 };
83 defer code_dir.root_dir.handle.close(io);
7884
7985 var in_file_reader = in_file.reader(io, &.{});
8086 const input_file_bytes = try in_file_reader.interface.allocRemaining(arena, .limited(max_doc_file_size));
......@@ -988,7 +994,7 @@ fn genHtml(
988994 io: Io,
989995 tokenizer: *Tokenizer,
990996 toc: *Toc,
991 code_dir: Dir,
997 code_dir: Path,
992998 out: *Writer,
993999) !void {
9941000 for (toc.nodes) |node| {
......@@ -1044,8 +1050,13 @@ fn genHtml(
10441050 });
10451051 defer allocator.free(out_basename);
10461052
1047 const contents = code_dir.readFileAlloc(io, out_basename, allocator, .limited(std.math.maxInt(u32))) catch |err| {
1048 return parseError(tokenizer, code.token, "unable to open '{s}': {t}", .{ out_basename, err });
1053 const out_path: Path = .{
1054 .root_dir = code_dir.root_dir,
1055 .sub_path = out_basename,
1056 };
1057
1058 const contents = out_path.root_dir.handle.readFileAlloc(io, out_path.sub_path, allocator, .unlimited) catch |err| {
1059 return parseError(tokenizer, code.token, "failed opening {f}: {t}", .{ out_path, err });
10491060 };
10501061 defer allocator.free(contents);
10511062