Skip to content

Commit

Permalink
"Collapse" JSON parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnau478 committed May 13, 2024
1 parent 2731955 commit 681686d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@ pub fn getOptions(allocator: std.mem.Allocator, args: argparse.ParseResult, stdo
}
};

const parsed = try std.json.parseFromSlice(OptionalDisplayOptions, allocator, source, .{});
const parsed = std.json.parseFromSlice(OptionalDisplayOptions, allocator, source, .{}) catch |err| switch (err) {
error.OutOfMemory,
error.Overflow,
=> return error.OutOfMemory,
error.InvalidCharacter,
error.UnexpectedToken,
error.InvalidNumber,
error.InvalidEnumTag,
error.DuplicateField,
error.UnknownField,
error.MissingField,
error.LengthMismatch,
error.SyntaxError,
error.UnexpectedEndOfInput,
error.BufferUnderrun,
error.ValueTooLong,
=> return error.InvalidConfig,
};
defer parsed.deinit();

inline for (std.meta.fields(OptionalDisplayOptions)) |field| {
Expand Down

0 comments on commit 681686d

Please sign in to comment.