From 729391ee25abeb40215158d58deba37c028431fe Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 12 Jan 2022 10:30:59 +0100 Subject: [PATCH] Bug 29857: Provide a generic full_message method for our exceptions We pass useful information when throwing exceptions, but we don't display them! We must display all the details we need when the exception is stringified. Test plan: Use the following snippet: use Koha::Exceptions::Elasticsearch; Koha::Exceptions::Elasticsearch::BadResponse->throw( type => "a good type", details => "and some details" ); Execute it without and with the patch. --- Koha/Exceptions/Exception.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Koha/Exceptions/Exception.pm b/Koha/Exceptions/Exception.pm index 8955ea9e6ee..5dfe20f7ef4 100644 --- a/Koha/Exceptions/Exception.pm +++ b/Koha/Exceptions/Exception.pm @@ -9,4 +9,17 @@ use Exception::Class ( }, ); +sub full_message { + my $self = shift; + my $msg = $self->description; + my @fields; + my $field_hash = $self->field_hash; + while ( my ( $field, $value ) = each %$field_hash ) { + push @fields, $field . " => " . $value; + } + return + sprintf "Exception '%s' thrown '%s'" . ( @fields ? " with %s" : "" ) . "\n", + ref($self), $msg, ( @fields ? join ', ', @fields : () ); +} + 1; -- 2.25.1