From 74e0dfb4376c971d916299827aca1d65cd0852a1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Apr 2018 12:39:15 -0300 Subject: [PATCH] Bug 20590: Improve Koha::Exceptions in string context I was working on bug 20580 and noticed that the exceptions are not stringified and so not really useful when displayed in string context. This patch is for discussion and not ready for inclusion Still need to fix: Koha/REST/V1/Patrons.pm (The error is "Given xxx does not exist") Koha/Object.pm: in ->store, Koha::Exceptions::Object::FKConstraint is raised but we cannot set 'value' Another note: In Koha::Exceptions::Exception I do not have access to $self->line_number and $self->filename See also http://search.cpan.org/~drolsky/Exception-Class-1.44/lib/Exception/Class/Base.pm#OVERRIDING_THE_as_string_METHOD Test plan: Apply patch from bug 20580 and execute create_superlibrarian.pl with an invalid categorycode Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Members.pm | 6 +++--- Koha/Exceptions.pm | 5 +---- Koha/Exceptions/Object.pm | 5 ++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index f4fd79e1dc..a901a961bc 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -400,9 +400,9 @@ sub AddMember { my $category = Koha::Patron::Categories->find( $data{categorycode} ); unless ($category) { - Koha::Exceptions::BadParameter->throw( - error => 'Invalid parameter passed', - parameter => 'categorycode' + Koha::Exceptions::Object::FKConstraint->throw( + broken_fk => 'categorycode', + value => $data{categorycode}, ); } diff --git a/Koha/Exceptions.pm b/Koha/Exceptions.pm index f49a289901..72a56cc3af 100644 --- a/Koha/Exceptions.pm +++ b/Koha/Exceptions.pm @@ -1,13 +1,10 @@ package Koha::Exceptions; use Modern::Perl; +use Koha::Exceptions::Exception; use Exception::Class ( - # General exceptions - 'Koha::Exceptions::Exception' => { - description => 'Something went wrong!', - }, 'Koha::Exceptions::BadParameter' => { isa => 'Koha::Exceptions::Exception', description => 'A bad parameter was given', diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm index 4cad568347..451c677c5f 100644 --- a/Koha/Exceptions/Object.pm +++ b/Koha/Exceptions/Object.pm @@ -3,9 +3,8 @@ package Koha::Exceptions::Object; use Modern::Perl; use Exception::Class ( - 'Koha::Exceptions::Object' => { - description => 'Something went wrong!', + isa => 'Koha::Exceptions::Exception', }, 'Koha::Exceptions::Object::DuplicateID' => { isa => 'Koha::Exceptions::Object', @@ -15,7 +14,7 @@ use Exception::Class ( 'Koha::Exceptions::Object::FKConstraint' => { isa => 'Koha::Exceptions::Object', description => "Foreign key constraint broken", - fields => ['broken_fk'] + fields => ['broken_fk', 'value'], }, 'Koha::Exceptions::Object::MethodNotFound' => { isa => 'Koha::Exceptions::Object', -- 2.39.5