Koha-clms/Koha/Exceptions
Tomás Cohen Arazi 033cfd772c
Bug 42391: (follow-up) Add NotNull, NotInStorage and UnhandledDBError translations
Extend the ExceptionTranslator to handle two additional MySQL error
patterns:

- NOT NULL violations ('Column X cannot be null' and 'X doesn't have
  a default value') → Koha::Exceptions::Object::NotNull
- Not in database errors → Koha::Exceptions::Object::NotInStorage

Add Koha::Exceptions::Object::NotNull exception class with a property
field identifying the offending column.

Add Koha::Exceptions::Object::UnhandledDBError as a catch-all for DBI
errors that don't match any known pattern. This closes the gap where
unmatched MySQL errors could leak as DBIx::Class::Exception to callers
(e.g. templates that no longer catch that type).

The exception_action handler now distinguishes three cases:
- Koha exception objects (from txn_do re-throws): passed through via
  'die $msg' to preserve the original exception type. Without this,
  txn_do's rollback-and-rethrow would stringify the Koha exception
  and wrap it in UnhandledDBError, losing the specific type.
- DBI errors (prefixed 'DBI Exception:'): translated if possible,
  otherwise wrapped in UnhandledDBError.
- DBIC internal errors (e.g. 'Not in database'): translated if
  possible, otherwise thrown as DBIx::Class::Exception.

Note: NotInStorage translation works for update operations but not for
delete-on-detached-Row where DBIC bypasses the Schema's exception_action.
Those cases remain DBIx::Class::Exception.

Update tests:
- OAIServers.t, Z3950Servers.t: assert NotNull with property check
- Hold.t: assert NotNull, remove warn suppression hack
- Objects.t: update-not-in-storage cases assert NotInStorage
- Upload.t: delete-not-in-storage stays DBIx::Class::Exception

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
2026-07-20 12:44:54 +00:00
..
Acquisition Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Checkouts Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ERM/EUsage Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Item Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Patron Bug 39014: (follow-up) Refactoring and renaming to can_be_guaranteed_by 2025-12-30 07:49:05 -07:00
Account.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ApiKey.pm Bug 20638: Add revoke() and activate() methods to Koha::ApiKey 2026-01-22 09:26:00 -07:00
ArticleRequest.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Auth.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Authentication.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Authorization.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
BackgroundJob.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Booking.pm Bug 29002: Add bookings objects and API classes 2023-11-03 12:04:07 -03:00
Calendar.pm
…
Checkin.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Checkout.pm
…
CirculationRule.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
ClubHold.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
Config.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
CurbsidePickup.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Elasticsearch.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Hold.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
HoldGroup.pm Bug 40517: (follow-up) Fix GNU license links 2025-10-29 11:50:12 -06:00
Ill.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Library.pm Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
MarcOverlayRule.pm Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
Metadata.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Object.pm Bug 42391: (follow-up) Add NotNull, NotInStorage and UnhandledDBError translations 2026-07-20 12:44:54 +00:00
Password.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Patron.pm Bug 42764: Fix spelling errors across the codebase 2026-06-03 16:09:04 +00:00
Plugin.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Preservation.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
REST.pm Bug 28907: Add REST exceptions for public routes auth 2025-03-06 13:54:29 +01:00
Report.pm Bug 41919: Limit number of current reports a single user can run simultaneously 2026-05-07 07:56:21 -06:00
Suggestion.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
SysPref.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Token.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
TransferLimit.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
Virtualshelf.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
XSLT.pm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00