Bugzilla – Attachment 186645 Details for
Bug 19871
Use new exceptions Koha::Exceptions::Object::DuplicateID and FKConstraint
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19871: Use centralized exception translation in Koha::Item::add_to_bundle
Bug-19871-Use-centralized-exception-translation-in.patch (text/plain), 3.15 KB, created by
Martin Renvoize (ashimema)
on 2025-09-21 15:14:47 UTC
(
hide
)
Description:
Bug 19871: Use centralized exception translation in Koha::Item::add_to_bundle
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-09-21 15:14:47 UTC
Size:
3.15 KB
patch
obsolete
>From e6a87020ebd76ded906e9b725bc6066722655738 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Sun, 21 Sep 2025 12:34:09 +0100 >Subject: [PATCH] Bug 19871: Use centralized exception translation in > Koha::Item::add_to_bundle > >Replace duplicated DBIx::Class exception handling code with the new >centralized exception translation system introduced in the previous commit. > >This change: >- Eliminates ~40 lines of duplicated exception handling code >- Uses the new Koha::Schema::translate_exception() method >- Maintains identical exception behavior and error messages >- Addresses the FIXME comment requesting this refactoring > >The add_to_bundle method now uses consistent exception translation >with the rest of the codebase, reducing maintenance burden and >ensuring consistent error handling patterns. >--- > Koha/Item.pm | 39 ++------------------------------------- > 1 file changed, 2 insertions(+), 37 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index c675d0638e4..1e615b18f6a 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -2326,43 +2326,8 @@ sub add_to_bundle { > ); > } catch { > >- # FIXME: See if we can move the below copy/paste from Koha::Object::store into it's own class and catch at a lower level in the Schema instantiation, take inspiration from DBIx::Error >- if ( ref($_) eq 'DBIx::Class::Exception' ) { >- if ( $_->{msg} =~ /Cannot add or update a child row: a foreign key constraint fails/ ) { >- >- # FK constraints >- # FIXME: MySQL error, if we support more DB engines we should implement this for each >- if ( $_->{msg} =~ /FOREIGN KEY \(`(?<column>.*?)`\)/ ) { >- Koha::Exceptions::Object::FKConstraint->throw( >- error => 'Broken FK constraint', >- broken_fk => $+{column} >- ); >- } >- } elsif ( $_->{msg} =~ /Duplicate entry '(.*?)' for key '(?<key>.*?)'/ ) { >- Koha::Exceptions::Object::DuplicateID->throw( >- error => 'Duplicate ID', >- duplicate_id => $+{key} >- ); >- } elsif ( $_->{msg} =~ /Incorrect (?<type>\w+) value: '(?<value>.*)' for column \W?(?<property>\S+)/ ) >- { # The optional \W in the regex might be a quote or backtick >- my $type = $+{type}; >- my $value = $+{value}; >- my $property = $+{property}; >- $property =~ s/['`]//g; >- Koha::Exceptions::Object::BadValue->throw( >- type => $type, >- value => $value, >- property => $property =~ /(\w+\.\w+)$/ >- ? $1 >- : $property, # results in table.column without quotes or backtics >- ); >- } >- >- # Catch-all for foreign key breakages. It will help find other use cases >- $_->rethrow(); >- } else { >- $_->rethrow(); >- } >+ # Use centralized exception translation instead of duplicated code >+ $schema->translate_exception($_); > }; > } > >-- >2.51.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 19871
:
186634
|
186635
|
186644
| 186645 |
186646
|
186647
|
186648
|
186649
|
186650