Bug 25952: Skip invalid repositories when searching for plugins

This patch prevents the end-user to get the ugly 500 "malformed JSON
string" when something wrong happens with the plugin search. It happens
currently in ktd with the plugin repos listed in $KOHA_CONF

An error is reported to the UI

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2025-11-14 12:02:34 +01:00 committed by Lucas Gass
parent d51dc1fc69
commit 438e51351d
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 72 additions and 56 deletions

View File

@ -85,6 +85,15 @@
</div> </div>
[% END %] [% END %]
[% IF search_errors %]
<h2>Search errors</h2>
<div class="page-section">
[% FOREACH error IN search_errors %]
<div class="alert alert-warning">Cannot search repository [% error.repo.name | html %]: [% error.error | html %]</div>
[% END %]
</div>
[% END %]
[% IF search_results %] [% IF search_results %]
<h2>Search results</h2> <h2>Search results</h2>
<div class="page-section"> <div class="page-section">

View File

@ -23,6 +23,7 @@ use CGI qw ( -utf8 );
use JSON qw( from_json ); use JSON qw( from_json );
use LWP::Simple qw( get ); use LWP::Simple qw( get );
use Try::Tiny;
use Koha::Plugins; use Koha::Plugins;
use C4::Auth qw( get_template_and_user ); use C4::Auth qw( get_template_and_user );
@ -63,7 +64,7 @@ if ($plugins_enabled) {
$template->param( plugins_restricted => C4::Context->config('plugins_restricted') ); $template->param( plugins_restricted => C4::Context->config('plugins_restricted') );
$template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 ); $template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
my @results; my ( @results, @errors );
if ($plugin_search) { if ($plugin_search) {
my $repos = C4::Context->config('plugin_repos'); my $repos = C4::Context->config('plugin_repos');
@ -73,6 +74,7 @@ if ($plugins_enabled) {
} }
foreach my $r ( @{ $repos->{repo} } ) { foreach my $r ( @{ $repos->{repo} } ) {
try {
if ( $r->{service} eq 'github' ) { if ( $r->{service} eq 'github' ) {
my $url = my $url =
"https://api.github.com/search/repositories?q=$plugin_search+user:$r->{org_name}+in:name,description"; "https://api.github.com/search/repositories?q=$plugin_search+user:$r->{org_name}+in:name,description";
@ -131,10 +133,15 @@ if ($plugins_enabled) {
} }
} }
} }
} catch {
warn $_;
push @errors, { repo => $r, error => $_ };
};
} }
$template->param( $template->param(
search_results => \@results, search_results => \@results,
search_errors => \@errors,
search_term => $plugin_search, search_term => $plugin_search,
); );
} }