authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 17:01:56 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 17:01:56 -07:00
logfba9092061e7b3ff6180d96f6edd2ad413082f80
treea1c26661c5ba9a2f67219f9495e749c629e4f3d8
parent2793e74b8fefef535b951221cdb440c4986f4af3

cleanup errors v2


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

json.zig+5-4
......@@ -3,7 +3,7 @@ const string = []const u8;
33const extras = @import("extras");
44const tracer = @import("tracer");
55
6const Error = std.mem.Allocator.Error || error{ MalformedJson, EndOfStream };
6const Error = error{ OutOfMemory, EndOfStream, MalformedJson };
77const ObjectHashMap = std.AutoArrayHashMapUnmanaged(StringIndex, ValueIndex);
88
99pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options: Parser.Options) (@TypeOf(inreader).Error || Error)!Document {
......@@ -28,7 +28,8 @@ pub fn parse(alloc: std.mem.Allocator, path: string, inreader: anytype, options:
2828 std.debug.assert(try p.addArray(alloc, &.{}) == .empty_array);
2929 std.debug.assert(try p.addObject(alloc, &ObjectHashMap{}) == .empty_object);
3030
31 const root = parseElement(alloc, &p) catch |err| return @errorCast(err);
31 const root_err: (@TypeOf(inreader).Error || Error)!ValueIndex = @errorCast(parseElement(alloc, &p));
32 const root = try root_err;
3233 if (p.avail() > 0) return error.MalformedJson;
3334 const data = try p.extras.toOwnedSlice(alloc);
3435
......@@ -351,10 +352,10 @@ const Parser = struct {
351352
352353 pub fn shift(p: *Parser) !u21 {
353354 try p.peekAmt(1) orelse return error.EndOfStream;
354 const len = try std.unicode.utf8ByteSequenceLength(p.slice()[0]);
355 const len = std.unicode.utf8ByteSequenceLength(p.slice()[0]) catch return error.MalformedJson;
355356 try p.peekAmt(len) orelse return error.EndOfStream;
356357 defer p.idx += len;
357 return std.unicode.utf8Decode(p.slice()[0..len]);
358 return std.unicode.utf8Decode(p.slice()[0..len]) catch return error.MalformedJson;
358359 }
359360
360361 pub fn shiftBytesN(p: *Parser, comptime n: usize) ![n]u8 {