Nix::getHydraNotifyPrometheusConfig: print errors if the configuration provided is invalid.

This commit is contained in:
Your Name 2021-08-24 11:35:38 -04:00
parent 4ebdcc290e
commit 24467a7bde

View file

@ -74,12 +74,22 @@ sub getHydraNotifyPrometheusConfig {
my ($config) = @_; my ($config) = @_;
my $cfg = $config->{hydra_notify}; my $cfg = $config->{hydra_notify};
if (!defined($cfg) || ref $cfg ne "HASH") { if (!defined($cfg)) {
return undef;
}
if (ref $cfg ne "HASH") {
print STDERR "Error reading Hydra's configuration file: hydra_notify should be a block.\n";
return undef; return undef;
} }
my $cfg = $cfg->{prometheus}; my $cfg = $cfg->{prometheus};
if (!defined($cfg) || ref $cfg ne "HASH") { if (!defined($cfg)) {
return undef;
}
if (ref $cfg ne "HASH") {
print STDERR "Error reading Hydra's configuration file: hydra_notify.prometheus should be a block.\n";
return undef; return undef;
} }
@ -88,6 +98,9 @@ sub getHydraNotifyPrometheusConfig {
"listen_address" => $cfg->{'listen_address'}, "listen_address" => $cfg->{'listen_address'},
"port" => $cfg->{'port'}, "port" => $cfg->{'port'},
}; };
} else {
print STDERR "Error reading Hydra's configuration file: hydra_notify.prometheus should include listen_address and port.\n";
return undef;
} }
return undef; return undef;