Bug 39632

Summary: Failed plugin install gives too little info
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Plugin architectureAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: kyle, martin.renvoize, tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: Trivial patch Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 39632: Extend plugin exceptions with more useful parameters
Bug 39632: Make plugin install and upgrade errors more useful
Bug 39632: Extend plugin exceptions with more useful parameters
Bug 39632: Make plugin install and upgrade errors more useful

Description Tomás Cohen Arazi (tcohen) 2025-04-14 18:48:23 UTC
When the `install()` process fails, it throws a `Koha::Exceptions::Plugin::InstallDied` exception. But it only carries the `plugin_class` value. We need to pass the error from the `try/catch` block so it gets returned to the caller as well.
Comment 1 Tomás Cohen Arazi (tcohen) 2025-04-14 19:21:25 UTC
Created attachment 180930 [details] [review]
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
Comment 2 Tomás Cohen Arazi (tcohen) 2025-04-14 19:21:27 UTC
Created attachment 180931 [details] [review]
Bug 39632: Make plugin install and upgrade errors more useful

This patch makes the install and upgrade process for plugins to add the
newly added extra parameters to the thrown exceptions.

This is covered by the tests

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ prove -r t/Koha/Exceptions.t \
           t/db_dependent/Koha/Plugins
=> SUCCESS: Tests pass!
3. Sign off :-D
Comment 3 Brendan Gallagher 2025-04-14 21:18:28 UTC
Created attachment 180942 [details] [review]
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>
Comment 4 Brendan Gallagher 2025-04-14 21:18:30 UTC
Created attachment 180943 [details] [review]
Bug 39632: Make plugin install and upgrade errors more useful

This patch makes the install and upgrade process for plugins to add the
newly added extra parameters to the thrown exceptions.

This is covered by the tests

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ prove -r t/Koha/Exceptions.t \
           t/db_dependent/Koha/Plugins
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>