Skip to content

Confusing error when passing invalid ID to synonym upsert() #233

Closed
@christiankaindl

Description

@christiankaindl

Description

When using the Synonym upsert() function in the Typesense JS SDK, invalid IDs throw an ambiguous error which doesn't give any clue on what the issue is or how to fix it.

Steps to reproduce

await typesenseClient.collections('myCollection').synonyms().upsert('Ärztinnen-/Ärzte-Ausbildungsordnung 2015', {
  synonyms: ['Syn 1', 'Syn 2'],
})

Edit: After some more testing, it seems that the slash ("/") is the problem, using umlaute ("ä") or non-breaking spaces as the ID seems to work just fine.

Expected Behavior

If the ID needs to match a certain format, I'd expect a informative error to be thrown, something the lines of "Invalid ID. IDs have to match format ".

As an alternative, invalid IDs could automatically be coerced to a valid one, or given a UUID. Though a useful error is probably more expected.

Actual Behavior

I get an error that caused us some confusion on how to fix it:

ObjectNotFound: Request failed with HTTP code 404 | Server said: Not Found
    at ObjectNotFound.TypesenseError [as constructor] (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/src/Typesense/Errors/TypesenseError.ts:6:10)
    at new ObjectNotFound (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/Errors/ObjectNotFound.js:25:42)
    at ApiCall.customErrorForResponse (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/src/Typesense/ApiCall.ts:424:15)
    at /Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/src/Typesense/ApiCall.ts:260:18
    at step (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/ApiCall.js:33:23)
    at Object.next (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/ApiCall.js:14:53)
    at step (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/ApiCall.js:18:139)
    at Object.next (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/ApiCall.js:14:53)
    at fulfilled (/Users/christiankaindl/Documents/GesetzeFinden.at/backend/node_modules/typesense/lib/Typesense/ApiCall.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  httpStatus: 404
}

Metadata

Typesense Version: Server 27.1; JS SDK 1.8.2

OS: macOS 15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions