From c87d8bd8fd7ded8c90dabdf1ec94bd566a58a621 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 28 Dec 2018 12:15:53 -0300 Subject: [PATCH] Bug 22051: Make Koha::Object->store translate incorrect value exceptions This patch adds a new condition to Koha::Object->store so it catches incorrect value-related DBIC exceptions. This DBIC exceptions get now translated into Koha::Exceptions::Object::BadValue exceptions with relevant parameters passed. To test: - Apply the exception and unit tests patches - Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests fail because this exception handling code is not implemented - Apply this patch - Run: k$ prove t/db_dependent/Koha/Object.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Owen Leonard Signed-off-by: Charles Farmer --- Koha/Object.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Koha/Object.pm b/Koha/Object.pm index 2dc135e..98867d2 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -143,6 +143,13 @@ sub store { duplicate_id => $+{key} ); } + elsif( $_->{msg} =~ /Incorrect (?\w+) value: '(?.*)' for column '(?\w+)'/ ) { + Koha::Exceptions::Object::BadValue->throw( + type => $+{type}, + value => $+{value}, + property => $+{property} + ); + } } # Catch-all for foreign key breakages. It will help find other use cases $_->rethrow(); -- 2.7.4