TBD54566975 / dwn-sdk-js

Decentralized Web Node (DWN) Reference implementation
https://identity.foundation/decentralized-web-node/spec/
Apache License 2.0
325 stars 96 forks source link

Replace silent failures with explicit failures in `index-level.ts` #633

Open thehenrytsai opened 10 months ago

thehenrytsai commented 10 months ago

In index-level.ts, there are at least a couple of places where we accept invalid input and either return void/empty array instead of throwing explicit errors.

It is probably better to throw instead so that the caller does not assume the method succeeds with no results:

  1. queryWithInMemoryPaging()
      // if a cursor is provided but we cannot find it, we return an empty result set
      return [];
  1. getStartingKeyForCursor()
    if (indexes === undefined) {
      // invalid itemId
      return;
    }

    const sortValue = indexes[property];
    if (sortValue === undefined) {
      // invalid sort property
      return;
    }
lchauha commented 10 months ago

Hi @thehenrytsai I would like to work on this issue. Can you please assign this to me?

lchauha commented 10 months ago

The two methods that you have specified above, I can't find them in index-level.ts file. Were these (queryWithInMemoryPaging(), getStartingKeyForCursor() ) examples?

lchauha commented 10 months ago

I have just found one place where we are not returning anything in the index-level.ts file.

https://github.com/TBD54566975/dwn-sdk-js/blob/main/src/store/index-level.ts#L157C14-L157C14, this is the only place.

Let me know if there are more of these.

LiranCohen commented 10 months ago

Hi @lchauha! This is an Issue related to an existing PR that's being merged in. We preemptively created this Issue to address some things in a separate PR.

Keep an eye out for this PR #625 to be merged and then you will be able to pick this up.