From 24467a7bdede3945dcbec4a35454931a7571848d Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 24 Aug 2021 11:35:38 -0400 Subject: [PATCH] Nix::getHydraNotifyPrometheusConfig: print errors if the configuration provided is invalid. --- src/lib/Hydra/Helper/Nix.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index ac0e54cf..bd294b73 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -74,12 +74,22 @@ sub getHydraNotifyPrometheusConfig { my ($config) = @_; 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; } 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; } @@ -88,6 +98,9 @@ sub getHydraNotifyPrometheusConfig { "listen_address" => $cfg->{'listen_address'}, "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;