From 8e96b550c579e6d414af67478ab80a8e221a201d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 18 Jul 2023 15:05:50 -0300 Subject: [PATCH] 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 --- Koha/CirculationRules.pm | 3 ++- Koha/Exceptions/CirculationRule.pm | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Koha/Exceptions/CirculationRule.pm diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 8065cf827f5..8518aa6112a 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -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 ) { diff --git a/Koha/Exceptions/CirculationRule.pm b/Koha/Exceptions/CirculationRule.pm new file mode 100644 index 00000000000..a43d248a430 --- /dev/null +++ b/Koha/Exceptions/CirculationRule.pm @@ -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 . + +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; -- 2.41.0