typesense / typesense/typesense-js

Import with empty array fails

Open
#188 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
569
Forks
99
Avg merge
5h 6m
Merged PRs (30d)
2

Description

Description

Calling the import function with an empty array fails.

Steps to reproduce

Initialize a collection and try to call import with an empty array:

const documents = [];

return await tsClient
  .collections<T>('testcollection')
  .documents()
  .import(documents); // this fails

Expected Behavior

It doesn't fail.

Actual Behavior

It fails with this error:

/Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342
        .map((r) => JSON.parse(r)) as ImportResponse[];
         ^
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342:26
    at Array.map (<anonymous>)
    at Documents.<anonymous> (/Users/<path-to-project>/node_modules/typesense/src/Typesense/Documents.ts:342:10)
    at step (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:48:23)
    at Object.next (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:29:53)
    at fulfilled (/Users/<path-to-project>/node_modules/typesense/lib/Typesense/Documents.js:20:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Metadata

Typesense Version: 0.25.1

OS: Run in Docker

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Typesense/Documents.ts around line 342, where the import response is parsed, and reproduce the issue with the empty documents array from the report. The work is complete when importing an empty array no longer fails with an unexpected-end-of-JSON error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.