Bugzilla – Attachment 130011 Details for
Bug 29857
We must stringify our exceptions correctly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29857: Fix behavior
Bug-29857-Fix-behavior.patch (text/plain), 2.10 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-01-31 15:18:16 UTC
(
hide
)
Description:
Bug 29857: Fix behavior
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-01-31 15:18:16 UTC
Size:
2.10 KB
patch
obsolete
>From 4cb6939bffdfb116e1f130ef1f6fcc313e4fbd45 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 31 Jan 2022 12:07:02 -0300 >Subject: [PATCH] Bug 29857: Fix behavior > >This patch makes: >- passed parameters be rendered alphabetically to allow testing. >- only the defined parameters be rendered in the string >- the method honor the fact that $self->message should be returned if > passed to the constructor (i.e. if the developer called >Koha::Exceptions::MyException->throw( $string ) they will expect $string >to be rendered. > >To test: >1. Apply the unit tests patch >2. Run: > $ kshell > k$ prove t/Koha/Exceptions.t >=> FAIL: Tests fail! >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Tests pass! >5. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Exception.pm | 37 ++++++++++++++++++++++++++++++++----- > 1 file changed, 32 insertions(+), 5 deletions(-) > >diff --git a/Koha/Exception.pm b/Koha/Exception.pm >index 69702d2936..7e5b195867 100644 >--- a/Koha/Exception.pm >+++ b/Koha/Exception.pm >@@ -10,15 +10,42 @@ use Exception::Class ( > > sub full_message { > my $self = shift; >- my $msg = $self->description; >- my @fields; >+ >+ # If a message was passed manually, return it >+ return $self->message >+ if $self->message; >+ > my $field_hash = $self->field_hash; >- while ( my ( $field, $value ) = each %$field_hash ) { >- push @fields, $field . " => " . $value; >+ >+ my $description = $self->description; >+ my @fields; >+ >+ foreach my $key ( sort keys %$field_hash ) { >+ push @fields, $key . " => " . $field_hash->{$key} >+ if defined $field_hash->{$key}; > } >+ > return > sprintf "Exception '%s' thrown '%s'" . ( @fields ? " with %s" : "" ) . "\n", >- ref($self), $msg, ( @fields ? join ', ', @fields : () ); >+ ref($self), $description, ( @fields ? join ', ', @fields : () ); > } > >+=head1 NAME >+ >+Koha::Exception - Base class for exceptions >+ >+=head1 Exceptions >+ >+=head2 Koha::Exception >+ >+Generic exception. >+ >+=head1 Class methods >+ >+=head2 full_message >+ >+Generic method for exception stringifying. >+ >+=cut >+ > 1; >-- >2.32.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29857
:
129329
|
129330
|
130007
|
130008
|
130009
|
130010
|
130011
|
130012
|
130013
|
130014
|
130015
|
130156
|
130157
|
130158
|
130355
|
131112
|
131113
|
131114
|
131115
|
131116
|
131117
|
131232
|
131240
|
131241
|
131242
|
131243
|
131244
|
131256
|
131258
|
131287
|
131288
|
131289
|
131290
|
131291