From: Jacob Bachmeyer Date: Thu, 3 Nov 2022 20:41:12 +0000 (-0500) Subject: Add structured exception for filename mismatch X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c937147c0a296da620b3ce5a3cefb641a81fbc0c;p=gatekeeper.git Add structured exception for filename mismatch This commit also changes the exception handling for exceptions carrying long-form messages, instead of continuing to list their types individually and removes testsuite support for a long-obsolete log message that could never actually be produced. --- diff --git a/gatekeeper.pl b/gatekeeper.pl index f25e9b4..1bcdd52 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -555,6 +555,22 @@ BEGIN { sub package_name { (shift)->{package_name} } } +{ + package Local::Exception::directive_filename_mismatch; + {our @ISA = qw(Local::Exception)} + + sub summary { + my $self = shift; + return "filename element mismatch: $self->{filename} expecting $self->{stem}"} + + sub message { my $self = shift; return <<"END" } +The filename directive element does not match the name of the uploaded file. + + Declared name: $self->{filename} + Uploaded file: $self->{stem} +END +} + { package Local::Exception::directive_syntax; {our @ISA = qw(Local::Exception)} @@ -2057,10 +2073,9 @@ sub validate_commands { # directive signature and the uploaded packet. We already know that # the name of the uploaded file must match the stem of the directive # file name; this is how it was recognized as part of the packet. - fatal("The filename directive does not match name of the uploaded file." - ."\n\n Filename directive: $op_header->{filename}" - ."\n Uploaded file: $stem\n",1) - unless $stem eq $op_header->{filename}; + throw directive_filename_mismatch => + filename => $op_header->{filename}, stem => $stem + unless $stem eq $op_header->{filename}; } } @@ -2620,8 +2635,8 @@ foreach my $packet (@packets) { # each list element is an array reference mail(join("\n",$E->summary,'',$E->trace_msg),1); } elsif ($E->type_p('package_configuration')) { mail($E->summary,0); - } elsif ($E->type_p('signature_replay') - || $E->type_p('unknown_package')) { + } elsif (UNIVERSAL::can($E, 'message')) { + # catch-all for exceptions carrying long-form messages mail($E->message,1); } } else { diff --git a/testsuite/lib/gatekeeper.exp b/testsuite/lib/gatekeeper.exp index 41dbc2a..b6b15ec 100644 --- a/testsuite/lib/gatekeeper.exp +++ b/testsuite/lib/gatekeeper.exp @@ -736,18 +736,11 @@ proc analyze_log { base_dir name assess } { exp_continue } -re {^gatekeeper\[[0-9]+\]: \(Test\) \[PV\]\ - The filename directive does not match name of the\ - uploaded file.[^\r\n]+} { + filename element mismatch: [^\r\n]+} { # from read_directive_file, on name mismatch set A(validate,filename-mismatch) 1 exp_continue } - -re {^gatekeeper\[[0-9]+\]: \(Test\) \[PV\]\ - filename [^\r\n]+ does not match name of directive[^\r\n]+} { - # from read_directive_file, on name mismatch - set A(validate,filename-mismatch-directive) 1 - exp_continue - } -re {^gatekeeper\[[0-9]+\]: \(Test\) \[AA\]\ DEBUG: Signature made [^\r\n]+} { # from read_directive_file, reporting signature timestamp