ndk icon indicating copy to clipboard operation
ndk copied to clipboard

WASM cache adapter: binding undefined causes Wrong API use error

Open dergigi opened this issue 3 months ago • 4 comments

Summary

When using NDKCacheAdapterSqliteWasm inside our Next.js app, queries that include author filters (e.g. free by:ross) intermittently crash with the following runtime error:

Wrong API use : tried to bind a value of an unknown type (undefined).

Environment

  • @nostr-dev-kit/ndk-cache-sqlite-wasm 0.5.8
  • @nostr-dev-kit/ndk 2.14.33
  • Next.js 15.4.6 (React 19)
  • Running in dev mode (next dev)

Reproduction

  1. Configure NDK with new NDKCacheAdapterSqliteWasm({ name: 'ants-cache', size: 64 }).
  2. Issue a search query containing an author clause such as free by:ross via searchEvents().
  3. The sqlite worker throws the error above (originating from setParameter inside worker.b59ef1cc.js).

The same query works fine when switching back to the Dexie cache adapter. Looks like the WASM cache attempts to bind an undefined parameter instead of a string/number.

Could you add a guard (or coerce to empty string) before binding, or otherwise handle undefined values gracefully?

Thanks!

dergigi avatar Sep 28 '25 12:09 dergigi

Error: Wrong API use : tried to bind a value of an unknown type (undefined).
    at coerceError (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/next-devtools/userspace/app/errors/stitched-error.js:53:73)
    at onUnhandledError (webpack-internal:///(app-pages-browser)/./node_modules/next/dist/next-devtools/userspace/app/errors/use-error-handler.js:97:54)

dergigi avatar Sep 28 '25 12:09 dergigi

this is likely because a subscription is being created with a null or undefined value like

authors: [null] or "#e": [undefined]

I'm about to cut a new version that filters the filters (🥁) to ensure that they are correctly formed and optionally fix them.

pablof7z avatar Sep 30 '25 10:09 pablof7z

I published it yesterday; it will now throw when you pass an invalid filter so that you (you claude-code, of course) can get rid of the line sending the invalid filter.

pablof7z avatar Oct 02 '25 08:10 pablof7z

that filters the filters (🥁)

😂

published it yesterday

🫶

dergigi avatar Oct 02 '25 13:10 dergigi