Bug 30367

Summary: Plugins: Search explodes in error when searching for specific keywords
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: Plugin architectureAssignee: Nick Clemens (kidclamp) <nick>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: andrew, danyonsewell, david, jonathan.druart, lucas, nick
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29787
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.06,22.05.14
Circulation function:
Attachments: Bug 30367: Skip processing if we don't get releases
Bug 30367: Skip processing if we don't get releases
Bug 30367: (follow-up) Same adjustment for gitlab
Bug 30367: Skip processing if we don't get releases
Bug 30367: (follow-up) Same adjustment for gitlab

Description Katrin Fischer 2022-03-26 23:51:21 UTC
This was found testing bug 29787 so I'll copy part of the test plan here:


To test:
1. Have this on your koha-conf.xml file:

 <plugin_repos>
    <repo>
        <name>ByWater Solutions</name>
        <org_name>bywatersolutions</org_name>
        <service>github</service>
    </repo>
    <repo>
        <name>Theke Solutions</name>
        <org_name>thekesolutions</org_name>
        <service>gitlab</service>
    </repo>
    <repo>
        <name>PTFS Europe</name>
        <org_name>ptfs-europe</org_name>
        <service>github</service>
    </repo>
 </plugin_repos>

2. Restart all services:
   $ restart_all
3. Search for the term 'barclaycard'

The search will give an error:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/JSON.pm line 190

It might be an issue with the plugin, but we should catch errors in a nicer way for the users.
Comment 1 Katrin Fischer 2022-03-27 11:52:35 UTC
From bug 29787:

(In reply to Tomás Cohen Arazi from comment #9)
> Maybe GitHub API changed. ByWater and PTFS both are on GitHub while Theke's
> is on Gitlab.
Comment 2 Andrew Fuerste-Henry 2022-03-27 13:15:57 UTC
Thanks for filing this! We've known for a while that searching for "edifact" doesn't work, but haven't gotten around to putting a bug in. I know it used to just return no results, rather than a 500 error. I don't know when that changed.
Comment 3 Nick Clemens (kidclamp) 2023-05-02 16:30:44 UTC
Created attachment 150523 [details] [review]
Bug 30367: Skip processing if we don't get releases

Some repos don't have releases, and this seems to break things as get returns an empty
response. Calling from_json on this is the error

This simply skips the bad responses to avoid the error:

To test:
1. Have this on your koha-conf.xml file:

 <plugin_repos>
    <repo>
        <name>ByWater Solutions</name>
        <org_name>bywatersolutions</org_name>
        <service>github</service>
    </repo>
    <repo>
        <name>Theke Solutions</name>
        <org_name>thekesolutions</org_name>
        <service>gitlab</service>
    </repo>
    <repo>
        <name>PTFS Europe</name>
        <org_name>ptfs-europe</org_name>
        <service>github</service>
    </repo>
 </plugin_repos>

2. Restart all services:
   $ restart_all
3. Search for the term 'barclaycard'

The search will give an error:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/JSON.pm line 190
4. Apply patch
5. Repeat
6. No error

Note: The barclaycard plugin won't install even though it is returned as of this note - the plugin needs an update I believe, I don't think it's a Koha issue
Comment 4 David Nind 2023-05-02 17:25:34 UTC
Created attachment 150527 [details] [review]
Bug 30367: Skip processing if we don't get releases

Some repos don't have releases, and this seems to break things as get returns an empty
response. Calling from_json on this is the error

This simply skips the bad responses to avoid the error:

To test:
1. Have this on your koha-conf.xml file:

 <plugin_repos>
    <repo>
        <name>ByWater Solutions</name>
        <org_name>bywatersolutions</org_name>
        <service>github</service>
    </repo>
    <repo>
        <name>Theke Solutions</name>
        <org_name>thekesolutions</org_name>
        <service>gitlab</service>
    </repo>
    <repo>
        <name>PTFS Europe</name>
        <org_name>ptfs-europe</org_name>
        <service>github</service>
    </repo>
 </plugin_repos>

2. Restart all services:
   $ restart_all
3. Search for the term 'barclaycard'

The search will give an error:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/JSON.pm line 190
4. Apply patch
5. Repeat
6. No error

Note: The barclaycard plugin won't install even though it is returned as of this note - the plugin needs an update I believe, I don't think it's a Koha issue

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2023-05-02 17:28:23 UTC
Testing notes (using KTD):

1. To search (step 3), go to Administration > Plugins > Manage plugins.

2. Searching for 'barclaycard' didn't generate an error, but searching for 'edifact' did.
Comment 6 Jonathan Druart 2023-05-03 07:45:18 UTC
You are fixing for github, not gitlab.
Comment 7 Nick Clemens (kidclamp) 2023-05-03 10:59:47 UTC
Created attachment 150572 [details] [review]
Bug 30367: (follow-up) Same adjustment for gitlab

This adds the same update for gitlab code. I was unable to trigger the error,
however, I confirm searching for 'PayPal' returns a result after this patch
as well as before.
Comment 8 Jonathan Druart 2023-05-03 11:45:29 UTC
Created attachment 150575 [details] [review]
Bug 30367: Skip processing if we don't get releases

Some repos don't have releases, and this seems to break things as get returns an empty
response. Calling from_json on this is the error

This simply skips the bad responses to avoid the error:

To test:
1. Have this on your koha-conf.xml file:

 <plugin_repos>
    <repo>
        <name>ByWater Solutions</name>
        <org_name>bywatersolutions</org_name>
        <service>github</service>
    </repo>
    <repo>
        <name>Theke Solutions</name>
        <org_name>thekesolutions</org_name>
        <service>gitlab</service>
    </repo>
    <repo>
        <name>PTFS Europe</name>
        <org_name>ptfs-europe</org_name>
        <service>github</service>
    </repo>
 </plugin_repos>

2. Restart all services:
   $ restart_all
3. Search for the term 'barclaycard'

The search will give an error:

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/JSON.pm line 190
4. Apply patch
5. Repeat
6. No error

Note: The barclaycard plugin won't install even though it is returned as of this note - the plugin needs an update I believe, I don't think it's a Koha issue
Signed-off-by: David Nind <david@davidnind.com>

JD amended patch: fix indentation

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Jonathan Druart 2023-05-03 11:45:31 UTC
Created attachment 150576 [details] [review]
Bug 30367: (follow-up) Same adjustment for gitlab

This adds the same update for gitlab code. I was unable to trigger the error,
however, I confirm searching for 'PayPal' returns a result after this patch
as well as before.

JD amended patch: fix indentation

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 10 Tomás Cohen Arazi (tcohen) 2023-05-05 13:14:54 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 11 Martin Renvoize (ashimema) 2023-05-12 15:12:38 UTC
Many hands makes light work, thankyou everyone!

Pushed to 22.11.x for the next release
Comment 12 Lucas Gass (lukeg) 2023-06-13 16:15:24 UTC
Backported to 22.05.x for upcoming 22.05.14
Comment 13 Danyon Sewell 2023-07-20 01:37:05 UTC
Not backporting for 21.11.x