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 <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2018-04-16 12:39:15 -03:00
parent 0797d9cc09
commit 74e0dfb437
3 changed files with 6 additions and 10 deletions

View File

@ -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},
);
}

View File

@ -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',

View File

@ -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',