Bugzilla – Attachment 83723 Details for
Bug 22051
Make Koha::Object->store translate 'Incorrect <type> value' exceptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22051: Add Koha::Exceptions::Object::WrongValue
Bug-22051-Add-KohaExceptionsObjectWrongValue.patch (text/plain), 3.53 KB, created by
Josef Moravec
on 2019-01-08 18:19:32 UTC
(
hide
)
Description:
Bug 22051: Add Koha::Exceptions::Object::WrongValue
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2019-01-08 18:19:32 UTC
Size:
3.53 KB
patch
obsolete
>From bdb58a3bf4a468018929556bc2e3477c397679d8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 28 Dec 2018 11:33:13 -0300 >Subject: [PATCH] Bug 22051: Add Koha::Exceptions::Object::WrongValue > >This patch adds a new exception to be thrown in Koha::Object->store when >a DBIC exception is thrown regarding bad data format. > >To test: >- Apply this patch >- Run: > $ kshell > k$ prove t/Koha/Exceptions.t >=> SUCCESS: Tests pass! >- Sign off :-D > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Charles Farmer <charles.farmer@inLibro.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Exceptions/Object.pm | 12 ++++++++++++ > t/Koha/Exceptions.t | 21 ++++++++++++++++++++- > 2 files changed, 32 insertions(+), 1 deletion(-) > >diff --git a/Koha/Exceptions/Object.pm b/Koha/Exceptions/Object.pm >index 9569182..d36d9dc 100644 >--- a/Koha/Exceptions/Object.pm >+++ b/Koha/Exceptions/Object.pm >@@ -45,6 +45,11 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Object', > description => "Method not covered by tests", > }, >+ 'Koha::Exceptions::Object::BadValue' => { >+ isa => 'Koha::Exceptions::Object', >+ description => 'Invalid data passed', >+ fields => ['type', 'property', 'value'], >+ }, > ); > > sub full_message { >@@ -56,6 +61,9 @@ sub full_message { > if ( $self->isa('Koha::Exceptions::Object::FKConstraint') ) { > $msg = sprintf("Invalid parameter passed, %s=%s does not exist", $self->broken_fk, $self->value ); > } >+ elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) { >+ $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type ); >+ } > } > > return $msg; >@@ -91,6 +99,10 @@ Exception to be used when an invalid object property has been requested. > > Exception to be used when the invoked method is not covered by tests. > >+=head2 Koha::Exceptions::Object::BadValue >+ >+Exception to be used when a bad value has been passed for a property. >+ > =head1 Class methods > > =head2 full_message >diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t >index 7ecc115..f1be981 100644 >--- a/t/Koha/Exceptions.t >+++ b/t/Koha/Exceptions.t >@@ -22,7 +22,7 @@ use Test::Exception; > > subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub { > >- plan tests => 5; >+ plan tests => 9; > > use_ok('Koha::Exceptions::Object'); > >@@ -39,6 +39,25 @@ subtest 'Koha::Exceptions::Object::FKConstraint tests' => sub { > 'Koha::Exceptions::Object::FKConstraint', > 'Exception is thrown :-D'; > is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' ); >+ >+ throws_ok { >+ Koha::Exceptions::Object::BadValue->throw( >+ type => 'datetime', >+ property => 'a_property', >+ value => 'a_value' >+ ); >+ } >+ 'Koha::Exceptions::Object::BadValue', >+ 'Koha::Exceptions::Object::BadValue exception is thrown :-D'; >+ >+ # stringify the exception >+ is( "$@", 'Invalid value passed, a_property=a_value expected type is datetime', 'Koha::Exceptions::Object::BadValue stringified correctly' ); >+ >+ throws_ok >+ { Koha::Exceptions::Object::BadValue->throw( "Manual message exception" ) } >+ 'Koha::Exceptions::Object::BadValue', >+ 'Koha::Exceptions::Object::BadValue is thrown :-D'; >+ is( "$@", 'Manual message exception', 'Koha::Exceptions::Object::BadValue not stringified if manually passed' ); > }; > > subtest 'Koha::Exceptions::Password tests' => sub { >-- >2.1.4
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 22051
:
83534
|
83535
|
83536
|
83622
|
83623
|
83624
|
83657
|
83658
|
83659
| 83723 |
83724
|
83725