summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-01 05:04:57 -0300
committerGabriel Schneider <[email protected]>2026-10-01 05:18:09 -0300
commit51ddaaf3917ad7968df877d10580d1eadb926688 (patch)
treebedad9f6f2c1b04a34c76599ed126fc61b2b5ac9 /src/dump.zig
parent250db41743f77ce3d8421f729bdea0065aa6bc79 (diff)
downloadpardes-51ddaaf3917ad7968df877d10580d1eadb926688.tar.gz
pardes-51ddaaf3917ad7968df877d10580d1eadb926688.zip
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 <[email protected]>
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/dump.zig b/src/dump.zig
index f8b99ef4..e76bb1a2 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -396,11 +396,20 @@ pub const Parsed = struct {
/// Whether `bytes` are a dump a Restore could load, saying nothing: a
/// Restore asks before it warns about unsaved text or replaces anything.
-pub fn check(gpa: std.mem.Allocator, bytes: []const u8) !void {
+/// Whether `bytes` are a dump; a ZON failure's line and reason are left in
+/// `why`, ended by a 0.
+pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: []u8) !void {
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const source = try arena.allocator().dupeZ(u8, bytes);
- try validate(try std.zon.parse.fromSliceAlloc(State, arena.allocator(), source, null, .{ .free_on_error = false }));
+ var diag: std.zon.parse.Diagnostics = .{};
+ const state = std.zon.parse.fromSliceAlloc(State, arena.allocator(), source, &diag, .{ .free_on_error = false }) catch |err| {
+ const said = pardes.Messages.zonWhy(&diag, why[0 .. why.len - 1]);
+ if (said.ptr != why.ptr) @memcpy(why[0..said.len], said);
+ why[said.len] = 0;
+ return err;
+ };
+ try validate(state);
}
pub fn readZon(gpa: std.mem.Allocator, bytes: []const u8, label: []const u8) !Parsed {