From 3357630a7eea97d5e5c5707cd7e2cf9a6cba9314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 14 Apr 2025 16:08:42 -0300 Subject: [PATCH] Bug 39632: Extend plugin exceptions with more useful parameters This patch tweaks the `Koha::Exceptions::Plugin` class by adding an extra parameter to the plugin install and upgrade related exceptions so they carry the actuall error (if any). * Koha::Exceptions::Plugin::InstallDied: install_error * Koha::Exceptions::Plugin::UpgradeDied: upgrade_error I didn't pick plain 'error' because it is a reserved word for `Exception::Class` which makes it stringify using its value only. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/Koha/Exceptions.t => SUCCESS: Tests pass! 3. Sign off :-D --- Koha/Exceptions/Plugin.pm | 8 ++++---- t/Koha/Exceptions.t | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Koha/Exceptions/Plugin.pm b/Koha/Exceptions/Plugin.pm index 585e89cbbd5..4293ccc5347 100644 --- a/Koha/Exceptions/Plugin.pm +++ b/Koha/Exceptions/Plugin.pm @@ -35,12 +35,12 @@ use Exception::Class ( 'Koha::Exceptions::Plugin::InstallDied' => { isa => 'Koha::Exceptions::Plugin', description => 'The plugin died on install', - fields => ['plugin_class'], + fields => [ 'plugin_class', 'install_error' ], }, 'Koha::Exceptions::Plugin::UpgradeDied' => { isa => 'Koha::Exceptions::Plugin', description => 'The plugin died on upgrade', - fields => ['plugin_class'], + fields => [ 'plugin_class', 'upgrade_error' ], }, ); @@ -56,9 +56,9 @@ sub full_message { $self->plugin_name, $self->method ); } elsif ( $self->isa('Koha::Exceptions::Plugin::InstallDied') ) { - $msg = sprintf( "Calling 'install' died for plugin %s", $self->plugin_class ); + $msg = sprintf( "Calling 'install' died for plugin %s: %s", $self->plugin_class, $self->install_error ); } elsif ( $self->isa('Koha::Exceptions::Plugin::UpgradeDied') ) { - $msg = sprintf( "Calling 'upgrade' died for plugin %s", $self->plugin_class ); + $msg = sprintf( "Calling 'upgrade' died for plugin %s: %s", $self->plugin_class, $self->upgrade_error ); } } diff --git a/t/Koha/Exceptions.t b/t/Koha/Exceptions.t index 37a48a2c413..592af87b65f 100755 --- a/t/Koha/Exceptions.t +++ b/t/Koha/Exceptions.t @@ -315,24 +315,31 @@ subtest 'Koha::Exceptions::Plugin tests' => sub { use_ok("Koha::Exceptions::Plugin"); my $plugin_class = 'yahey'; + my $error_string = 'This is an error'; throws_ok { - Koha::Exceptions::Plugin::InstallDied->throw( plugin_class => $plugin_class ); + Koha::Exceptions::Plugin::InstallDied->throw( + plugin_class => $plugin_class, + install_error => $error_string, + ); } 'Koha::Exceptions::Plugin::InstallDied', 'Exception is thrown :-D'; # stringify the exception - is( "$@", "Calling 'install' died for plugin $plugin_class", 'Exception stringified correctly' ); + is( "$@", "Calling 'install' died for plugin $plugin_class: $error_string", 'Exception stringified correctly' ); throws_ok { - Koha::Exceptions::Plugin::UpgradeDied->throw( plugin_class => $plugin_class ); + Koha::Exceptions::Plugin::UpgradeDied->throw( + plugin_class => $plugin_class, + upgrade_error => $error_string, + ); } 'Koha::Exceptions::Plugin::UpgradeDied', 'Exception is thrown :-D'; # stringify the exception - is( "$@", "Calling 'upgrade' died for plugin $plugin_class", 'Exception stringified correctly' ); + is( "$@", "Calling 'upgrade' died for plugin $plugin_class: $error_string", 'Exception stringified correctly' ); }; subtest 'Koha::Exceptions::Booking tests' => sub { -- 2.49.0