From 7dd692699614f5843b0ab26438d085f1f892a05b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 16 Mar 2021 11:22:17 +0100 Subject: [PATCH] Bug 27557: Display stacktrace on 500 for superlibrarian From pod for Plack::Middleware::StackTrace: """ Gathering the information for a stack trace via Devel::StackTrace is slow, and Devel::StackTrace::WithLexicals is significantly slower still. This is not usually a concern in development and when exceptions are rare. However, your application may include code that's throwing and catching exceptions that you're not aware of. Such code will run significantly slower with this module. """ Maybe we should avoid the stacktrace and prefer to retrieve the error only, without the stacktrace? (but how?) cp C4/Auth.pm /usr/share/koha/lib/C4/Auth.pm cp debian/templates/plack.psgi /etc/koha/sites/kohadev/plack.psgi cp errors/500.pl /usr/share/koha/intranet/cgi-bin/errors/500.pl cp koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt /usr/share/koha/intranet/htdocs/intranet-tmpl/prog/en/modules/errors/errorpage.tt restart_all --- debian/templates/plack.psgi | 1 + errors/500.pl | 5 +++++ .../data/mysql/atomicupdate/bug_27557.perl | 12 ++++++++++++ .../en/modules/admin/preferences/logs.pref | 6 ++++++ .../prog/en/modules/errors/errorpage.tt | 19 +++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_27557.perl diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 89cd6ef48f..785e9d1df3 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -108,6 +108,7 @@ builder { #NOTE: Without this middleware to catch fatal errors, ErrorDocument won't be able to render a 500 document #NOTE: This middleware must be closer to the PSGI app than ErrorDocument enable "HTTPExceptions"; + enable "StackTrace", no_print_errors => 1; if ( Log::Log4perl->get_logger('plack-intranet')->has_appenders ){ enable 'Log4perl', category => 'plack-intranet'; enable 'LogWarn'; diff --git a/errors/500.pl b/errors/500.pl index f580b45b20..5c58494b8c 100755 --- a/errors/500.pl +++ b/errors/500.pl @@ -38,6 +38,11 @@ $template->param ( admin => $admin, errno => 500, ); +if ( C4::Context->preference('DumpStacktraceOn500') && C4::Context->IsSuperLibrarian ) { + $template->param( + stacktrace => $ENV{'plack.stacktrace.text'}, + ); +} my $status = '500 Internal Server Error'; if ( C4::Auth::psgi_env() ) { $status = '200 OK'; diff --git a/installer/data/mysql/atomicupdate/bug_27557.perl b/installer/data/mysql/atomicupdate/bug_27557.perl new file mode 100644 index 0000000000..194acf132b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_27557.perl @@ -0,0 +1,12 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) + VALUES ('DumpStacktraceOn500','0', 'Display the error on 500 for superlibrarians.', 'YesNo') + |); + + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 27557, "Add new syspref DumpStacktraceOn500"); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref index 490a69569d..9e25d4a45f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref @@ -110,3 +110,9 @@ Logging: 1: Do 0: "Don't" - dump search query as a template parameter, requires DumpTemplateVars[interface] to be visible. + - + - pref: DumpStacktraceOn500 + choices: + 1: Do + 0: "Don't" + - display a stacktrace of the error on 500 for superlibrarians. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt index 6cd94c19fc..2832350c68 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/errors/errorpage.tt @@ -1,3 +1,4 @@ +[% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Error [% errno | html %] [% INCLUDE 'doc-head-close.inc' %] @@ -22,6 +23,10 @@
  • You tried to access a page that needs authentication
  • An internal link in the client is broken and the page does not exist
  • + [% IF stacktrace %] +

    Detail of the error [show]

    + + [% END %]

    What's next?