diff --git a/bin/account-manager.pl.in b/bin/account-manager.pl.in
index c170ed26c959b48007a5c1f48d8f1eb6a3457317..ff6bd5d06f89b1a0afce96e7399812d5fc1a140d 100755
--- a/bin/account-manager.pl.in
+++ b/bin/account-manager.pl.in
@@ -142,12 +142,15 @@ sub list_accounts {
                 db => $db
             );
 
-        die "failed to update simpleSAMLphp configuration file\n"
-            unless IdPAccountManager::Tools::update_ssp_authsources(
+        eval {
+            IdPAccountManager::Tools::update_ssp_authsources(
                 $configuration->{templates_dir},
                 $configuration->{idp_accounts_file},
                 $accounts
             );
+        };
+        die "failed to update simpleSAMLphp configuration file: $EVAL_ERROR"
+            if $EVAL_ERROR;
 
         printf "Update simpleSamlPhp configuration file...\n";
     }
diff --git a/lib/IdPAccountManager/Tools.pm b/lib/IdPAccountManager/Tools.pm
index c641f9755bcadc5e18c732c61cda974b0484bcce..cf8dc9e2efab76702777474c870ef58f168d6c41 100644
--- a/lib/IdPAccountManager/Tools.pm
+++ b/lib/IdPAccountManager/Tools.pm
@@ -90,7 +90,7 @@ sub update_ssp_authsources {
         accounts => $accounts
     };
 
-    return $tt2->process($template, $data, $output);
+    $tt2->process($template, $data, $output) or die $tt2->error();
 }
 
 1;
diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm
index 5580245a5fe174b337d96616d903cc0839de57b1..c87f50d0ad13ae681ed0ccd4dc199e56755f2c0f 100755
--- a/lib/IdPAccountManager/WebRequest.pm
+++ b/lib/IdPAccountManager/WebRequest.pm
@@ -485,14 +485,18 @@ sub req_validate_token {
     }
 
     ## Update simpleSAMLphp configuration to enable test accounts
-    unless (IdPAccountManager::Tools::update_ssp_authsources(
+    eval {
+    IdPAccountManager::Tools::update_ssp_authsources(
             $self->{configuration}->{templates_dir},
             $self->{configuration}->{idp_accounts_file},
             \@accounts
-        )) {
+        );
+    };
+    if ($EVAL_ERROR) {
         push @{ $self->{out}->{errors} }, "accounts_creation_failed";
-        $self->{logger}->error(
-            "Failed to create simpleSAMLphp configuration file"
+        $self->{logger}->errorf(
+            "Failed to create simpleSAMLphp configuration file: %s",
+            $EVAL_ERROR
         );
         return undef;
     }