Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unexpected end of JSON input" error #243

Open
tomika opened this issue Nov 15, 2024 · 2 comments
Open

"Unexpected end of JSON input" error #243

tomika opened this issue Nov 15, 2024 · 2 comments

Comments

@tomika
Copy link

tomika commented Nov 15, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

On updating typesense database I often get the following error:

SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at (./node_modules/typesense/src/Typesense/Documents.ts:355:26)
at Array.map ()
at Documents. (./node_modules/typesense/src/Typesense/Documents.ts:355:10)
at step (./node_modules/typesense/lib/Typesense/Documents.js:48:23)
at Object.next (./node_modules/typesense/lib/Typesense/Documents.js:29:53)
at fulfilled (./node_modules/typesense/lib/Typesense/Documents.js:20:58)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Here is the diff that solved my problem:

diff --git a/node_modules/typesense/src/Typesense/Documents.ts b/node_modules/typesense/src/Typesense/Documents.ts
index b4ba7b3..1679569 100644
--- a/node_modules/typesense/src/Typesense/Documents.ts
+++ b/node_modules/typesense/src/Typesense/Documents.ts
@@ -352,6 +352,7 @@ export default class Documents<T extends DocumentSchema = object>
     if (Array.isArray(documents)) {
       const resultsInJSONFormat = resultsInJSONLFormat
         .split("\n")
+        .filter((r) => r.trim() !== "")
         .map((r) => JSON.parse(r)) as ImportResponse[];
       const failedItems = resultsInJSONFormat.filter(
         (r) => r.success === false,

This issue body was partially generated by patch-package.

Please consider to apply this patch!
Thank you in advance,
Tom

@arpadgabor
Copy link

We also started facing this issue, seems like the problem actually stems from some changes on the server, because 26.0 didn't cause this for us.

@tharropoulos
Copy link
Contributor

We also started facing this issue, seems like the problem actually stems from some changes on the server, because 26.0 didn't cause this for us.

Could you provide a reproducible example that would match that case? I'll try it out with different server versions so I can find a solution that serves both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants