config: store unknown errors in list too

This commit is contained in:
Mitchell Hashimoto
2023-09-11 09:14:27 -07:00
parent 75e8d8f0da
commit a359641d07

View File

@ -78,7 +78,15 @@ pub fn parse(comptime T: type, alloc: Allocator, dst: *T, iter: anytype) !void {
parseIntoField(T, arena_alloc, dst, key, value) catch |err| { parseIntoField(T, arena_alloc, dst, key, value) catch |err| {
if (comptime !canTrackErrors(T)) return err; if (comptime !canTrackErrors(T)) return err;
switch (err) {
// The error set is dependent on comptime T, so we always add
// an extra error so we can have the "else" below.
const ErrSet = @TypeOf(err) || error{Unknown};
switch (@as(ErrSet, @errSetCast(err))) {
// OOM is not recoverable since we need to allocate to
// track more error messages.
error.OutOfMemory => return err,
error.InvalidField => try dst._errors.add(arena_alloc, .{ error.InvalidField => try dst._errors.add(arena_alloc, .{
.message = try std.fmt.allocPrintZ( .message = try std.fmt.allocPrintZ(
arena_alloc, arena_alloc,
@ -103,7 +111,13 @@ pub fn parse(comptime T: type, alloc: Allocator, dst: *T, iter: anytype) !void {
), ),
}), }),
else => return err, else => try dst._errors.add(arena_alloc, .{
.message = try std.fmt.allocPrintZ(
arena_alloc,
"{s}: unknown error {}",
.{ key, err },
),
}),
} }
}; };
} }