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>
(cherry picked from commit 438e51351d)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
(cherry picked from commit a69f7a88ab)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
This commit is contained in:
Jonathan Druart 2025-11-14 12:02:34 +01:00 committed by Baptiste Wojtkowski
parent c5e942294a
commit 87039166c7
No known key found for this signature in database
GPG Key ID: 47A8A13E10BC0D40
2 changed files with 17 additions and 1 deletions

View File

@ -83,6 +83,15 @@
</div>
[% 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 %]
<h2>Search results</h2>
<div class="page-section">

View File

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