Explorar o código

Keep the reason when a render and its error page both fail

When a render failed and the 500 page could not be rendered either, yeet()
logged the method and route of the data before it died with the reason.  A
component render's data has neither, so the log line itself died with "Use
of uninitialized value", under fatal warnings, and that was the error the
caller got.  The reason for the failure was lost.

Now the log line says "?" for what the data lacks, and FATAL() dies with the
reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot hai 3 días
pai
achega
df25eafa99
Modificáronse 2 ficheiros con 21 adicións e 1 borrados
  1. 1 1
      lib/Trog/Renderer.pm
  2. 20 0
      t/Trog-Renderer.t

+ 1 - 1
lib/Trog/Renderer.pm

@@ -53,7 +53,7 @@ my sub yeet ( $renderer, $error, %options ) {
         $msg .= " and subsequently during render of error template, $@" if $renderer;
 
         #XXX bytes is probably not correct here
-        INFO( "$options{data}{method} 500 " . length($msg) . " $options{data}{route}" );
+        INFO( ( $options{data}{method} // '?' ) . ' 500 ' . length($msg) . ' ' . ( $options{data}{route} // '?' ) );
         FATAL($msg);
     };
     return $ret;

+ 20 - 0
t/Trog-Renderer.t

@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use 5.040;
+use re '/aasx';
+use warnings FATAL => 'all';
+
+use Test::More;
+use Test::Fatal qw{exception};
+
+use FindBin::libs;
+
+require_ok('Trog::Renderer') or BAIL_OUT("Can't find SUT");
+
+subtest 'a render that fails, and an error page that fails too' => sub {
+    my $err = exception {
+        Trog::Renderer->render( contenttype => 'text/html', component => 1, template => 'bogus-nothere.tx', data => {} );
+    };
+    like( $err, qr/Could[ ]not[ ]render[ ]template[ ]'bogus-nothere[.]tx'/, 'dies with the reason, for data that names no method or route' );
+};
+
+done_testing();