tigrisdata-archive / tigris-client-ts

TypeScript client for Tigris
https://www.tigrisdata.com/docs/sdkstools/typescript/
Apache License 2.0
15 stars 10 forks source link

Improve error messaging when a createOrUpdateIndex is called but the TigrisSearchIndex for the index hasn't been set #343

Closed leggetter closed 1 year ago

leggetter commented 1 year ago

Is your feature request related to a problem? Please describe. Given a model that doesn't have TigrisSearchIndex defined.

import {
  Field,
  PrimaryKey,
  SearchField,
  TigrisCollection,
  TigrisDataTypes,
} from "@tigrisdata/core";

export const PAGE_INDEX_NAME = "pages";

@TigrisCollection(PAGE_INDEX_NAME)
export class Page {
  @PrimaryKey(TigrisDataTypes.UUID, { order: 1, autoGenerate: true })
  id?: string;

  @Field()
  @SearchField({ facet: true, sort: true })
  title!: string;

  @Field()
  @SearchField()
  description!: string;

  @Field()
  @SearchField()
  content!: string;

  @Field()
  @SearchField({ facet: true })
  language!: string;
}

And code that tries to fetch the unset index:

import { Tigris } from "@tigrisdata/core";
import { Page } from "../src/db/models/pages";

async function main() {
  // setup client
  const tigrisClient = new Tigris();

  // If using Tigris Database
  // ensure branch exists, create it if it needs to be created dynamically
  await tigrisClient.getDatabase().initializeBranch();
  // register schemas
  await tigrisClient.registerSchemas([Page]);

  // If using Tigris Search
  // ensure the Search index is created or updated
  await tigrisClient.getSearch().createOrUpdateIndex<Page>(Page);
}

main()
  .then(async () => {
    console.log("Setup complete ...");
    process.exit(0);
  })
  .catch(async (e) => {
    console.error(e);
    process.exit(1);
  });

The developer will receive the error:

info - Using reflection to infer type of Page#title
info - Using reflection to infer type of Page#title
info - Using reflection to infer type of Page#description
info - Using reflection to infer type of Page#description
info - Using reflection to infer type of Page#content
info - Using reflection to infer type of Page#content
info - Using reflection to infer type of Page#language
info - Using reflection to infer type of Page#language
info - Using Tigris at: api.preview.tigrisdata.cloud:443
info - Using database branch: 'main'
event - Creating collection: 'pages' in project: 'astro-docs-example'
TypeError: Cannot read properties of undefined (reading 'target')
    at DecoratedSchemaProcessor.processIndex (/Users/leggetter/tmp/astro-docs-example/node_modules/@tigrisdata/core/dist/schema/decorated-schema-processor.js:20:53)
    at Search.createOrUpdateIndex (/Users/leggetter/tmp/astro-docs-example/node_modules/@tigrisdata/core/dist/search/search.js:21:57)
    at main (file:///Users/leggetter/tmp/astro-docs-example/scripts/setup.ts:16:34)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The error message TypeError: Cannot read properties of undefined (reading 'target') doesn't provide any clear indication of:

  1. What the problem is
  2. How to fix the problem

In this case, the developer, me, had made a mistake. But it took quite some time work out what the problem was.

Describe the solution you'd like I believe an error message such as An attempt was made to retrieve an index with the name "pages" but there is no index defined with that name. Please make sure an index has been defined using the 'TigrisSearchIndex' decorator would have been really helpful.

adilansari commented 1 year ago

/bounty $10

algora-pbc[bot] commented 1 year ago

πŸ’Ž $10.00 bounty created by adilansari πŸ™‹ If you start working on this, comment /attempt #343 to notify everyone πŸ‘‰ To claim this bounty, submit a pull request that includes the text /claim #343 somewhere in its body πŸ“ Before proceeding, please make sure you can receive payouts in your country πŸ’΅ Payment arrives in your account 2-5 days after the bounty is rewarded πŸ’― You keep 100% of the bounty award πŸ™ Thank you for contributing to tigrisdata/tigris-client-ts!

tachyonicbytes commented 1 year ago

/attempt #343

Hi! I would like to take a look at this!

algora-pbc[bot] commented 1 year ago

πŸ’‘ @tachyonicbytes submitted a pull request that claims the bounty. You can visit your org dashboard to reward.

algora-pbc[bot] commented 1 year ago

πŸŽ‰πŸŽˆ @tachyonicbytes has been awarded $10.00! 🎈🎊

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: