WASM cache adapter: binding undefined causes Wrong API use error
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-wasm0.5.8@nostr-dev-kit/ndk2.14.33- Next.js 15.4.6 (React 19)
- Running in dev mode (
next dev)
Reproduction
- Configure NDK with
new NDKCacheAdapterSqliteWasm({ name: 'ants-cache', size: 64 }). - Issue a search query containing an author clause such as
free by:rossviasearchEvents(). - The sqlite worker throws the error above (originating from
setParameterinsideworker.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!
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)
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.
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.
that filters the filters (🥁)
😂
published it yesterday
🫶