Bug 33028: Make exception less generic

While testing this bug I found Circulation.t was failing, but the
exception doesn't actually display anything useful in terms of helping
debug what's going on.

This patch makes it add the rule_name and rule_value to the message.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomás Cohen Arazi 2023-07-18 15:05:50 -03:00
parent 82bdaa8fbc
commit 9b7c077c9d
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 35 additions and 1 deletions

View file

@ -21,6 +21,7 @@ use Modern::Perl;
use Carp qw( croak );
use Koha::Exceptions;
use Koha::Exceptions::CirculationRule;
use Koha::CirculationRule;
use Koha::Caches;
use Koha::Cache::Memory::Lite;
@ -381,7 +382,7 @@ sub set_rule {
my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
$rule_value = undef if defined $rule_value && $rule_value eq "" && !$can_be_blank;
my $is_monetary = defined $kind_info->{is_monetary} ? $kind_info->{is_monetary} : 0;
Koha::Exceptions::BadParameter->throw("set_rule expected decimal")
Koha::Exceptions::CirculationRule::NotDecimal->throw( name => $rule_name, value => $rule_value )
if ( $is_monetary && defined($rule_value) && $rule_value !~ /^\d+(\.\d{2})?$/ );
for my $v ( $branchcode, $categorycode, $itemtype ) {

View file

@ -0,0 +1,33 @@
package Koha::Exceptions::CirculationRule;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Exception;
use Exception::Class (
'Koha::Exceptions::CirculationRule' => {
isa => 'Koha::Exception',
},
'Koha::Exceptions::CirculationRule::NotDecimal' => {
isa => 'Koha::Exceptions::CirculationRule',
description => "The circulation rule expected a decimal value",
fields => [ 'name', 'value' ],
},
);
1;