From 51ddaaf3917ad7968df877d10580d1eadb926688 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 05:04:57 -0300 Subject: Restore and ThemeFile failures say why in words, a ZON one with its line: never FileTooLarge, ParseZon or a bare `parse zon` Restore read failures named the Zig error (FileTooLarge, NotAFile, ReadFailed), a file that is no dump said `not a pardes dump (ParseZon)`, and a ThemeFile that did not parse said `parse zon`. Messages.errorWords says an error in words (the few that read badly spelled out plainly, the rest spaced and lower case, as reportError did), and zonWhy gives the parser's first error with its line: `not a pardes dump: line 1: expected ...`, `theme file x.zon: line 3: ...`. Co-Authored-By: Claude Opus 5.5 --- src/builtins.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/builtins.zig') diff --git a/src/builtins.zig b/src/builtins.zig index f51409aa..55779c8a 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -715,19 +715,22 @@ pub const Restore = struct { if (comptime pardes.hosted) { const bytes = @import("fs.zig").readRestore(c.p.gpa, path, c.p.settings.dump_dir.get()) catch |err| { var buf: [limits.host_path_cap + 64]u8 = undefined; + var words: [128]u8 = undefined; const why = switch (err) { error.FileNotFound => "no such file", error.PermissionDenied => "permission denied", error.IsDirectory => "a directory, not a dump", - else => @errorName(err), + else => pardes.Messages.errorWords(err, &words), }; return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: {s}", .{ path, why }) catch "Restore: cannot read the dump"); }; defer c.p.gpa.free(bytes); // Nor does a file that is not a dump, before any warning. - pardes.dump.check(c.p.gpa, bytes) catch |err| { - var buf: [limits.host_path_cap + 64]u8 = undefined; - return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: not a pardes dump ({s})", .{ path, @errorName(err) }) catch "Restore: not a pardes dump"); + var why_buf: [256]u8 = undefined; + pardes.dump.check(c.p.gpa, bytes, &why_buf) catch |err| { + var buf: [limits.host_path_cap + 320]u8 = undefined; + const why = if (err == error.ParseZon) why_buf[0..std.mem.indexOfScalar(u8, &why_buf, 0).?] else pardes.Messages.errorWords(err, &why_buf); + return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: not a pardes dump: {s}", .{ path, why }) catch "Restore: not a pardes dump"); }; } // acme's Load adds a dump's windows to the ones there; a Restore -- cgit v1.3