Add structured exception for package configuration errors
authorJacob Bachmeyer <jcb@gnu.org>
Thu, 3 Nov 2022 04:00:32 +0000 (23:00 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Thu, 3 Nov 2022 04:00:32 +0000 (23:00 -0500)
gatekeeper.pl

index 517c254adfe6a0f2e6c7b29502dada36f9c3b04c..dbc314425274d9d4fe86fd2fb00bf4ad7a2a52e8 100755 (executable)
@@ -548,6 +548,13 @@ BEGIN {
   }
 }
 
+{
+  package Local::Exception::package_configuration;
+  {our @ISA = qw(Local::Exception)}
+
+  sub package_name { (shift)->{package_name} }
+}
+
 {
   package Local::Exception::directive_syntax;
   {our @ISA = qw(Local::Exception)}
@@ -2535,7 +2542,12 @@ foreach my $packet (@packets) {  # each list element is an array reference
     $Phase = 'AA';
     # Check that we have a keyring for this package:
     my @keyrings = directory_keyrings($op_header->{directory});
-    fatal("no keyring for package $op_header->{package}",0) if ($#keyrings < 0);
+    unless (@keyrings) {
+      my $package = directory_package_name($op_header->{directory});
+      throw package_configuration =>
+       summary => "no keyring for package $package",
+       package_name => directory_package_name($op_header->{directory})
+    }
 
     $sig_info = verify_clearsigned_message($directive_text, @keyrings);
 
@@ -2581,6 +2593,8 @@ foreach my $packet (@packets) {   # each list element is an array reference
        mail($E->{message},$E->{send_to_user});
       } elsif ($E->type_p('directive_syntax')) {
        mail(join("\n",$E->{summary},'',$E->trace_msg),1);
+      } elsif ($E->type_p('package_configuration')) {
+       mail($E->{summary},0);
       }
     } else {
       # Exceptions thrown by perl itself come out as strings