Also warn about non-required values that are invalid

Before, only required values that were invalid produced a warning.
Non-required values were quietly ignored.
This commit is contained in:
Richard Hansen 2024-06-26 19:41:15 -04:00
parent 05dbe7a984
commit 70858e659f

View file

@ -2026,13 +2026,14 @@ sub init_config {
# is to validate command-line options which were merged into %globals above. # is to validate command-line options which were merged into %globals above.
# TODO: Move this check to where the command-line options are actually processed. # TODO: Move this check to where the command-line options are actually processed.
my $value = check_value($ovalue, $def); my $value = check_value($ovalue, $def);
# TODO: If the variable is not required, the value is set to undef but no warning is if (!defined($value)) {
# logged. Is that intentional? $ovalue //= '(not set)';
if ($def->{'required'} && !defined $value) { warning("ignoring invalid $def->{type} variable value '$k=$ovalue'");
# TODO: What's the point of this? The opt() function will fall back to the default if ($def->{'required'}) {
# value if $globals{$k} is undefined. # TODO: What's the point of this? The opt() function will fall back to the default
$value = default($k); # value if $globals{$k} is undefined.
warning("'%s=%s' is an invalid %s. (using default of %s)", $k, $ovalue, $def->{'type'}, $value); $value = default($k);
}
} }
$globals{$k} = $value; $globals{$k} = $value;
} }
@ -2071,13 +2072,15 @@ sub init_config {
# $config{$h} above. # $config{$h} above.
# TODO: Move this check to where --options is actually processed. # TODO: Move this check to where --options is actually processed.
my $value = check_value($ovalue, $def); my $value = check_value($ovalue, $def);
# TODO: If the variable is not required, the value is set to undef but no warning is if (!defined($value)) {
# logged. Is that intentional?
if ($def->{'required'} && !defined $value) {
$ovalue //= '(not set)'; $ovalue //= '(not set)';
warning("skipping host $h: invalid $def->{type} variable value '$k=$ovalue'"); if ($def->{'required'}) {
delete $config{$h}; warning("skipping host $h: invalid $def->{type} variable value '$k=$ovalue'");
next HOST; delete $config{$h};
next HOST;
} else {
warning("host $h: ignoring invalid $def->{type} variable value '$k=$ovalue'");
}
} }
$conf->{$k} = $value; $conf->{$k} = $value;
} }