diff --git a/lib/Ravada.pm b/lib/Ravada.pm index 04d093573..40d933ed2 100644 --- a/lib/Ravada.pm +++ b/lib/Ravada.pm @@ -747,7 +747,12 @@ sub _init_config { my $connector = shift; confess "Deprecated connector" if $connector; - $CONFIG = YAML::LoadFile($file); + die "ERROR: Missing config file $file\n" + if !-e $file; + + eval { $CONFIG = YAML::LoadFile($file) }; + + die "ERROR: Format error in config file $file\n$@" if $@; $LIMIT_PROCESS = $CONFIG->{limit_process} if $CONFIG->{limit_process} && $CONFIG->{limit_process}>1; diff --git a/t/05_ravada.t b/t/05_ravada.t index 136d66077..0fe91d2b3 100644 --- a/t/05_ravada.t +++ b/t/05_ravada.t @@ -16,4 +16,16 @@ ok($Ravada::CONNECTOR, "Now we should have a DB connector "); ok($Ravada::CONNECTOR,"No connector defined "); eval { ok($Ravada::CONNECTOR->dbh,"No dbh defined ") }; +eval { + my $config_err = "t/etc/ravada_miss.conf"; + my $rvd_err = Ravada->new( connector => $test->connector, config => $config_err); +}; +like($@,qr/Missing config file/); + +eval { + my $config_err = "t/etc/ravada_err.conf"; + my $rvd_err = Ravada->new( connector => $test->connector, config => $config_err); +}; +like($@,qr/Format error/); + done_testing();