From c67a6a960bc366eca0121dbdf4bdea43a4f28a3e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 13 Jan 2026 10:14:03 +0100 Subject: [PATCH] Bug 30803: Raise exception if $error is not passed Signed-off-by: Jonathan Druart --- C4/Output.pm | 5 +++++ t/Output.t | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/C4/Output.pm b/C4/Output.pm index e7d968cf050..f1d069c033a 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -45,6 +45,7 @@ use URI::Escape; use C4::Auth qw( get_template_and_user ); use C4::Context; use C4::Templates; +use Koha::Exceptions; =head1 NAME @@ -392,6 +393,10 @@ Missing POD for output_error. sub output_error { my ( $query, $error ) = @_; + + if ( !$error || $error =~ /\D/ ) { + Koha::Exceptions::WrongParameter->throw('output_error requires $error to be an integer'); + } my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => 'errors/errorpage.tt', diff --git a/t/Output.t b/t/Output.t index 3c022a3fab2..a3a5722a7aa 100755 --- a/t/Output.t +++ b/t/Output.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::NoWarnings; use Test::More tests => 10; use Test::Warn; +use Test::Exception; use Test::MockModule; use File::Temp qw/tempfile/; @@ -139,7 +140,7 @@ subtest 'output_and_exit_if_error() tests' => sub { }; subtest 'output_error' => sub { - plan tests => 2; + plan tests => 4; local *STDOUT; my $stdout; @@ -158,4 +159,13 @@ subtest 'output_error' => sub { like( $stdout, qr{Error 403}, '403 returned' ); close STDOUT; + throws_ok { + output_error($query); + } + 'Koha::Exceptions::WrongParameter'; + + throws_ok { + output_error( $query, "Error" ); + } + 'Koha::Exceptions::WrongParameter'; }; -- 2.43.0