config: fix regression where we halted parsing on deprecated field (#7719)
Fix regression from d44a6cde2c where we
halted parsing on deprecated fields, which was not the intended
behavior.
This commit fixes that and adds a test to verify it.
pull/7721/head
commit
67fe3d418a
|
|
@ -132,14 +132,20 @@ pub fn parse(
|
||||||
break :value null;
|
break :value null;
|
||||||
};
|
};
|
||||||
|
|
||||||
parseIntoField(T, arena_alloc, dst, key, value) catch |err| {
|
parseIntoField(T, arena_alloc, dst, key, value) catch |err| err: {
|
||||||
// If we get an error parsing a field, then we try to fall
|
// If we get an error parsing a field, then we try to fall
|
||||||
// back to compatibility handlers if able.
|
// back to compatibility handlers if able.
|
||||||
if (@hasDecl(T, "compatibility")) {
|
if (@hasDecl(T, "compatibility")) {
|
||||||
// If we have a compatibility handler for this key, then
|
// If we have a compatibility handler for this key, then
|
||||||
// we call it and see if it handles the error.
|
// we call it and see if it handles the error.
|
||||||
if (T.compatibility.get(key)) |handler| {
|
if (T.compatibility.get(key)) |handler| {
|
||||||
if (handler(dst, arena_alloc, key, value)) return;
|
if (handler(dst, arena_alloc, key, value)) {
|
||||||
|
log.info(
|
||||||
|
"compatibility handler for {s} handled error, you may be using a deprecated field: {}",
|
||||||
|
.{ key, err },
|
||||||
|
);
|
||||||
|
break :err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -838,6 +844,7 @@ test "parse: compatibility renamed" {
|
||||||
|
|
||||||
var data: struct {
|
var data: struct {
|
||||||
a: bool = false,
|
a: bool = false,
|
||||||
|
b: bool = false,
|
||||||
_arena: ?ArenaAllocator = null,
|
_arena: ?ArenaAllocator = null,
|
||||||
|
|
||||||
pub const compatibility: std.StaticStringMap(
|
pub const compatibility: std.StaticStringMap(
|
||||||
|
|
@ -850,12 +857,13 @@ test "parse: compatibility renamed" {
|
||||||
|
|
||||||
var iter = try std.process.ArgIteratorGeneral(.{}).init(
|
var iter = try std.process.ArgIteratorGeneral(.{}).init(
|
||||||
testing.allocator,
|
testing.allocator,
|
||||||
"--old=true",
|
"--old=true --b=true",
|
||||||
);
|
);
|
||||||
defer iter.deinit();
|
defer iter.deinit();
|
||||||
try parse(@TypeOf(data), testing.allocator, &data, &iter);
|
try parse(@TypeOf(data), testing.allocator, &data, &iter);
|
||||||
try testing.expect(data._arena != null);
|
try testing.expect(data._arena != null);
|
||||||
try testing.expect(data.a);
|
try testing.expect(data.a);
|
||||||
|
try testing.expect(data.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "parseIntoField: ignore underscore-prefixed fields" {
|
test "parseIntoField: ignore underscore-prefixed fields" {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue