extism / js-sdk

Run Extism WebAssembly plug-ins / functions from JavaScript (supports major browsers, Node.js, Deno, Bun, and Cloudflare Workers)
https://extism.github.io/js-sdk/
BSD 3-Clause "New" or "Revised" License
65 stars 10 forks source link

Improve error message when using async host functions with foreground plugins #41

Open chrisdickinson opened 11 months ago

chrisdickinson commented 11 months ago

Since async host functions are only supported by plugins running on background threads, we should throw an early error if any host functions are instanceof AsyncFunction. Additionally, we should catch any "could not convert Promise to BigInt"-style errors that are emitted during runtime and wrap them with some help text.

nilslice commented 3 months ago

Noting to anyone who finds this issue from an error message like:

SyntaxError: Cannot convert [object Promise] to a BigInt

async functions (or functions that explicitly return a promise) are only supported if runInWorker: true is passed to the plugin on initialization: https://github.com/extism/js-sdk/blob/main/examples/node.js#L15