Bug 20950 - Plugins: Handler.pm doesn't fail gracefully when running plugin
Summary: Plugins: Handler.pm doesn't fail gracefully when running plugin
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-15 10:55 UTC by Andrew Isherwood
Modified: 2020-04-05 02:17 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Isherwood 2018-06-15 10:55:56 UTC
When running a plugin that fails for some internal reason, the user doesn't always receive a very helpful message. With the Kitchen Sink plugin ( https://github.com/bywatersolutions/koha-plugin-kitchen-sink ) I managed to break it by trying to import C4::Members::GetMember - which doesn't exist any more.

Running the plugin in this broken state resulted in:

run.pl: Plugin Koha::Plugin::Com::ByWaterSolutions::KitchenSink cannot be loaded at /usr/share/koha/Koha/Plugins/Handler.pm line 72.: /usr/share/koha/plugins/run.pl

It turns out that Koha::Plugins::Handler::run calls Module::Load::Conditional::can_load, which was returning false, which caused the message I saw to be output. However, Module::Load::Conditional sets a global variable upon can_load returning false containing the reason. We should display this (assuming we don't consider it to be a security risk).

So, in Handler.pm, we'd need to substitute in:

if ( can_load( modules => { $plugin_class => undef } ) ) {
    my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } );
    if ( $plugin->can($plugin_method) ) {
        return $plugin->$plugin_method( $params );
    } else {
        warn "Plugin does not have method $plugin_method";
    }
} else {
    warn "Plugin $plugin_class cannot be loaded: " . $Module::Load::Conditional::ERROR;
}