Skip to content

ndk.fetchEvent() crashes app with invalid filter #357

@benjamindedonder

Description

@benjamindedonder

If I call ndk.fetchEvent() with an invalid filter, a filter with an invalid id, it throws the following error:

Error: Invalid filter(s) detected:
Filter[0].ids[0] is not a valid 64-char hex string: "invalid_id"

Which is fine, but not much later the entire app crashes with the following error:

file://<project_folder>/node_modules/@nostr-dev-kit/ndk/dist/index.mjs:11644
        s.stop();
        ^

ReferenceError: Cannot access 's' before initialization
    at Timeout._onTimeout (file://<project_folder>/node_modules/@nostr-dev-kit/ndk/dist/index.mjs:11644:9)
    at listOnTimeout (node:internal/timers:588:17)
    at process.processTimers (node:internal/timers:523:7)

I looked into your code a bit. I'm by far not experienced enough to understand everything or comment on anything. But my guess is it might be a simple fix right here:

s.stop();

I think a question mark was forgotten there? And it should be s?.stop(); instead?

I'm assuming the first error is thrown here:

s = this.subscribe(filters, subscribeOpts);

Which causes s never to be initialized.

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