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

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
Signed-off-by: Laura_Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit afd530ab0d)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomás Cohen Arazi 2025-04-14 16:08:42 -03:00 committed by Paul Derscheid
parent cd92d22bc0
commit 2e32cf12a5
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 15 additions and 8 deletions

View File

@ -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 );
}
}

View File

@ -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 {