diff --git a/Koha/Schema.pm b/Koha/Schema.pm index 0041f3062f..693c019caa 100644 --- a/Koha/Schema.pm +++ b/Koha/Schema.pm @@ -15,7 +15,7 @@ __PACKAGE__->load_namespaces; # Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:oDUxXckmfk6H9YCjW8PZTw -use Koha::Schema::Util::ExceptionTranslator; +use Koha::Schema::ExceptionMapper; =head1 UTILITY METHODS @@ -43,7 +43,7 @@ sub connection { # Attempt translation — throws a Koha exception on match # Handles both DBI errors and DBIC internal errors (e.g. "Not in database") - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); # No match — wrap DBI errors so DBIx::Class::Exception never leaks if ( $msg =~ /^DBI Exception:/ ) { diff --git a/Koha/Schema/Util/ExceptionTranslator.pm b/Koha/Schema/ExceptionMapper.pm similarity index 94% rename from Koha/Schema/Util/ExceptionTranslator.pm rename to Koha/Schema/ExceptionMapper.pm index 4593a2ddff..40ab8a3211 100644 --- a/Koha/Schema/Util/ExceptionTranslator.pm +++ b/Koha/Schema/ExceptionMapper.pm @@ -1,4 +1,4 @@ -package Koha::Schema::Util::ExceptionTranslator; +package Koha::Schema::ExceptionMapper; # Copyright 2025 Koha Development team # @@ -25,11 +25,11 @@ use Koha::Exceptions::Object; =head1 NAME -Koha::Schema::Util::ExceptionTranslator - Centralized DBIx::Class exception translation +Koha::Schema::ExceptionMapper - Centralized DBIx::Class exception translation =head1 SYNOPSIS - use Koha::Schema::Util::ExceptionTranslator; + use Koha::Schema::ExceptionMapper; # Called automatically via Koha::Schema's exception_action hook. # No manual invocation needed in normal code. @@ -45,7 +45,7 @@ are automatically translated before they propagate to callers. =head2 translate_exception - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); Attempts to translate a database error message into a Koha exception and throw it. If the message does not match any known pattern, returns without diff --git a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t b/t/db_dependent/Koha/Schema/ExceptionMapper.t old mode 100755 new mode 100644 similarity index 88% rename from t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t rename to t/db_dependent/Koha/Schema/ExceptionMapper.t index 99b587eedf..4c7b7615bb --- a/t/db_dependent/Koha/Schema/Util/ExceptionTranslator.t +++ b/t/db_dependent/Koha/Schema/ExceptionMapper.t @@ -23,7 +23,7 @@ use Test::More tests => 11; use Test::Exception; use Koha::Database; -use Koha::Schema::Util::ExceptionTranslator; +use Koha::Schema::ExceptionMapper; use t::lib::TestBuilder; @@ -39,7 +39,7 @@ subtest 'foreign_key_constraint_translation' => sub { "Cannot add or update a child row: a foreign key constraint fails (`koha`.`items`, CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`))"; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); } 'Koha::Exceptions::Object::FKConstraint', 'FK constraint exception is properly translated'; @@ -56,7 +56,7 @@ subtest 'duplicate_key_translation' => sub { my $msg = "Duplicate entry 'test\@example.com' for key 'borrowers.email'"; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); } 'Koha::Exceptions::Object::DuplicateID', 'Duplicate key exception is properly translated'; @@ -73,7 +73,7 @@ subtest 'bad_value_translation' => sub { my $msg = "Incorrect datetime value: '2025-13-45' for column 'date_due' at row 1"; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); } 'Koha::Exceptions::Object::BadValue', 'Bad value exception is properly translated'; @@ -90,7 +90,7 @@ subtest 'enum_truncation_translation' => sub { my $msg = "Data truncated for column 'status' at row 1"; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); } 'Koha::Exceptions::Object::BadValue', 'Enum truncation exception is properly translated'; @@ -105,7 +105,7 @@ subtest 'unmatched_message_returns' => sub { $schema->storage->txn_begin; my $msg = "Some unknown database error at row 1"; - my $result = Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + my $result = Koha::Schema::ExceptionMapper->translate_exception($msg); is( $result, undef, 'Unmatched message returns without throwing' ); @@ -121,7 +121,7 @@ subtest 'fk_constraint_deletion_translation' => sub { "Cannot delete or update a parent row: a foreign key constraint fails (`koha`.`items`, CONSTRAINT `items_ibfk_1` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`))"; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception($msg); + Koha::Schema::ExceptionMapper->translate_exception($msg); } 'Koha::Exceptions::Object::FKConstraintDeletion', 'FK constraint deletion exception is properly translated'; @@ -136,7 +136,7 @@ subtest 'not_null_translation' => sub { $schema->storage->txn_begin; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception("Column 'host' cannot be null"); + Koha::Schema::ExceptionMapper->translate_exception("Column 'host' cannot be null"); } 'Koha::Exceptions::Object::NotNull', 'NOT NULL violation is properly translated'; @@ -151,7 +151,7 @@ subtest 'not_in_database_translation' => sub { $schema->storage->txn_begin; throws_ok { - Koha::Schema::Util::ExceptionTranslator->translate_exception("Not in database"); + Koha::Schema::ExceptionMapper->translate_exception("Not in database"); } 'Koha::Exceptions::Object::NotInStorage', 'Not in database is properly translated';