Convert command-line argument warnings into fatal errors

This commit is contained in:
Richard Hansen 2024-07-01 22:07:11 -04:00
parent 18bd312216
commit 564b315bfa
2 changed files with 9 additions and 22 deletions

View file

@ -15,6 +15,9 @@ repository history](https://github.com/ddclient/ddclient/commits/master).
* The default web service for `--webv4` and `--webv6` has changed from Google * The default web service for `--webv4` and `--webv6` has changed from Google
Domains (which has shut down) to ipify. Domains (which has shut down) to ipify.
[5b104ad1](https://github.com/ddclient/ddclient/commit/5b104ad116c023c3760129cab6e141f04f72b406) [5b104ad1](https://github.com/ddclient/ddclient/commit/5b104ad116c023c3760129cab6e141f04f72b406)
* Invalid command-line options or values are now fatal errors (instead of
discarded with a warning).
[#TODO](https://github.com/ddclient/ddclient/pull/TODO)
* All log messages are now written to STDERR, not a mix of STDOUT and STDERR. * All log messages are now written to STDERR, not a mix of STDOUT and STDERR.
[#676](https://github.com/ddclient/ddclient/pull/676) [#676](https://github.com/ddclient/ddclient/pull/676)
* For `--protocol=freedns` and `--protocol=nfsn`, the core module * For `--protocol=freedns` and `--protocol=nfsn`, the core module

View file

@ -1953,19 +1953,12 @@ sub init_config {
for my $k (keys %globals) { for my $k (keys %globals) {
# TODO: This might grab an arbitrary protocol-specific variable, which could cause # TODO: This might grab an arbitrary protocol-specific variable, which could cause
# surprising behavior. # surprising behavior.
my $def = $variables{'merged'}{$k}; my $def = $variables{'merged'}{$k} or fatal("unknown option '$k=$globals{$k}'");
if (!$def) {
warning("ignoring unknown setting '$k=$globals{$k}'");
delete($globals{$k});
next;
}
# _read_config already checked any value from the config file, so the purpose of this check # _read_config already checked any value from the config file, so the purpose of this check
# 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.
if (!eval { $globals{$k} = check_value($globals{$k}, $def); 1; }) { eval { $globals{$k} = check_value($globals{$k}, $def); 1; }
warning("ignoring invalid variable value '$k=$globals{$k}': $@"); or fatal("invalid option value '$k=$globals{$k}': $@");
delete($globals{$k});
}
} }
## now the host definitions... ## now the host definitions...
@ -1978,9 +1971,7 @@ sub init_config {
load_json_support($proto) if (grep($_ eq $proto, ("1984", "cloudflare", "digitalocean", "directnic", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2"))); load_json_support($proto) if (grep($_ eq $proto, ("1984", "cloudflare", "digitalocean", "directnic", "gandi", "godaddy", "hetzner", "yandex", "nfsn", "njalla", "porkbun", "dnsexit2")));
if (!exists($protocols{$proto})) { if (!exists($protocols{$proto})) {
warning("skipping host: %s: unrecognized protocol '%s'", $h, $proto); fatal("host %s: unrecognized protocol: '%s'", $h, $proto);
delete $config{$h};
next;
} }
my $svars = $protocols{$proto}{'variables'}; my $svars = $protocols{$proto}{'variables'};
@ -1994,15 +1985,8 @@ sub init_config {
# check is to validate command-line options from --options which were merged into # check is to validate command-line options from --options which were merged into
# $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.
if (!eval { $conf->{$k} = check_value($config{$h}{$k}, $def); 1; }) { eval { $conf->{$k} = check_value($config{$h}{$k}, $def); 1; }
if ($def->{'required'}) { or fatal("host $h: invalid option value '$k=$config{$h}{$k}': $@");
warning("skipping host $h: invalid variable value '$k=$config{$h}{$k}': $@");
delete $config{$h};
next HOST;
} else {
warning("host $h: ignoring invalid variable value '$k=$config{$h}{$k}': $@");
}
}
} }
$config{$h} = $conf; $config{$h} = $conf;
} }