summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
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 {