From 7429f28cfc7a47a486a8ffb54473db4ed6292500 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. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/Exceptions/Exception.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Koha/Exceptions/Exception.pm b/Koha/Exceptions/Exception.pm index 8955ea9e6e..5dfe20f7ef 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;