Bugzilla – Attachment 110854 Details for
Bug 26555
Add a way for Koha::Object(s) to carry execution information
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26555: Add Koha::Object::Error
Bug-26555-Add-KohaObjectError.patch (text/plain), 3.99 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-09-28 13:54:24 UTC
(
hide
)
Description:
Bug 26555: Add Koha::Object::Error
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-09-28 13:54:24 UTC
Size:
3.99 KB
patch
obsolete
>From ff3bfb53143439463c061edabb829aef2f6bc6e1 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 28 Sep 2020 10:23:50 -0300 >Subject: [PATCH] Bug 26555: Add Koha::Object::Error > >This patch introduces a tiny class for encapsulating errors in >Koha::Object derived classes. > >To test: >1. Apply this patch >2. Run; > $ kshell > k$ prove t/Koha/Object/Error.t >=> SUCCESS: Tests pass! >3. Sign off :-D >--- > Koha/Object/Error.pm | 74 +++++++++++++++++++++++++++++++++++++++++++ > t/Koha/Object/Error.t | 45 ++++++++++++++++++++++++++ > 2 files changed, 119 insertions(+) > create mode 100644 Koha/Object/Error.pm > create mode 100755 t/Koha/Object/Error.t > >diff --git a/Koha/Object/Error.pm b/Koha/Object/Error.pm >new file mode 100644 >index 0000000000..d8a9912437 >--- /dev/null >+++ b/Koha/Object/Error.pm >@@ -0,0 +1,74 @@ >+package Koha::Object::Error; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use base qw(Class::Accessor); >+ >+use Koha::Exceptions; >+ >+__PACKAGE__->mk_ro_accessors(qw( error )); >+ >+=head1 NAME >+ >+Koha::Object::Error - Class encapsulating errors in Koha::Object-derived classes >+ >+=head1 SYNOPSIS >+ >+ my ($self, $params) = @_; >+ push @{$self->{_errors}} = Koha::Object::Error->new($params); >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 new >+ >+ my $error = Koha::Object::Error->new( >+ { >+ error => $some_error >+ } >+ ); >+ >+Create a new Koha::Object::Error object. >+ >+=cut >+ >+sub new { >+ my ( $class, $params ) = @_; >+ >+ my $error = $params->{error}; >+ >+ Koha::Exceptions::MissingParameter->throw( "Mandatory parameter missing: 'error'" ) >+ unless $error; >+ >+ my $self = $class->SUPER::new( >+ { >+ error => $error >+ } >+ ); >+ >+ return $self; >+} >+ >+=head1 AUTHOR >+ >+Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt> >+ >+=cut >+ >+1; >diff --git a/t/Koha/Object/Error.t b/t/Koha/Object/Error.t >new file mode 100755 >index 0000000000..176670e954 >--- /dev/null >+++ b/t/Koha/Object/Error.t >@@ -0,0 +1,45 @@ >+#!/usr/bin/perl >+ >+# Copyright 2019 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Exception; >+ >+BEGIN { >+ use_ok('Koha::Object::Error'); >+} >+ >+subtest 'new() tests' => sub { >+ >+ plan tests => 4; >+ >+ my $some_error = 'Some error'; >+ >+ my $error = Koha::Object::Error->new({ error => $some_error }); >+ is( ref($error), 'Koha::Object::Error', 'Type is correct' ); >+ is( $error->error, $some_error, 'The error attribute has the right value' ); >+ >+ throws_ok >+ { Koha::Object::Error->new({ blah => 'ohh' }); } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if required parameter missing'; >+ >+ is( "$@", "Mandatory parameter missing: 'error'", 'Expected exception message' ); >+}; >-- >2.28.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 26555
:
110854
|
110855
|
110911
|
110912
|
110913
|
110957
|
110958
|
110959
|
110967
|
110968
|
110969
|
110983
|
111426
|
111427
|
111428
|
111723