TypeError: implode(): Argument #1 ($array) must be of type array, string given in implode() (line 587 of modules/contrib/search_api_swiftype/src/Plugin/search_api/backend/SwiftypeBackend.php

Created on 24 October 2024, 28 days ago

Problem/Motivation

We are currently experiencing the following error during indexing:

TypeError: implode(): Argument #1 ($array) must be of type array, string given in implode() (line 587 of modules/contrib/search_api_swiftype/src/Plugin/search_api/backend/SwiftypeBackend.php

While checking the code at that position, I realized, that the variable $response<code> used in the <code>catch block comes from the preceeding try block, which does not sound like a good idea ;)

Steps to reproduce

  • Unfortunately we can't provide any steps to reproduce, because we do not know what is really happening due to the error

Proposed resolution

  • Rework logging so it either does not rely on the $response variable from the try block or handle the $response variable with a fallback or similiar, if it is undefined

Remaining tasks

  • Create issue fork and MR to fix this issue

User interface changes

n/a

API changes

n/a

Data model changes

n/a

🐛 Bug report
Status

Active

Version

10.0

Component

Code

Created by

🇩🇪Germany hctom

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @hctom
  • 🇮🇳India sarwan_verma

    Hi,
    I have resolved the "TypeError: implode(): Argument #1 ($array)" issue and created a patch.
    I have also attached the patch file .
    kindly review it,
    Thank!.

  • 🇮🇳India abhishek_virasat

    @sarwan_verma,

    Could you please ensure that you only pick up issues that are not already assigned to someone else? If an issue is already assigned, it's important to take note and avoid working on it. Overlooking this wastes time for both of us, as well as for others who may be working on the same issue. Remember, contribution is not just about earning credit; it's about respecting the efforts and time of everyone involved. Let's be mindful, considerate, and make the best use of our time.

  • 🇩🇪Germany stborchert

    There is no reason to be annoyed. You both tried to solve the problem.
    I created a new branch based on your changes.

  • 🇩🇪Germany hctom

    Thanks for the quick fix, this helped a lot, because now we know, that a cURL timeout is the underlying problem in our case.

    But with the current solution from the MR from #6, the $response variable is just completely empty, which results in a log message like this:

    Failed creating/updating documents: "cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.swiftype.com/api/v1/engines/SWIFTYPE-ENGINE-ID/document_types/entity-node/documents/bulk_create_or_update_verbose". Response:
    

    I guess the error handling should be able to deal with all of those cases:

    • No response at all (e.g. when a cURL error like ours occurred)
    • Array response (already covered)
    • String response (already covered)

    Additionally, it would also be nice, if the external IDs of the items to index may be included in the log message - because those are mostly very important to track done any underlying issues.

  • 🇮🇳India ushma

    ushma changed the visibility of the branch 10.x to hidden.

  • 🇮🇳India ushma

    ushma changed the visibility of the branch 10.x to active.

  • 🇮🇳India ushma

    @hctom Added logic to handle empty response case. Also attached a patch for the same. Please review.

Production build 0.71.5 2024