js-pdk icon indicating copy to clipboard operation
js-pdk copied to clipboard

`assert` blows up in v1.3.0

Open mhmd-azeez opened this issue 1 year ago โ€ข 11 comments

index.ts:

import { Test } from "@dylibso/xtp-test";

export function test() {
  Test.assert("test", true, "because it's true");
  return 0;
}

extism-js v1.3.0

PS D:\dylibso\xtp\cli\app> go run . plugin test https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm --with D:\x\extism\assertbug\dist\plugin.wasm
thread '<unnamed>' panicked at crates/core/src/globals.rs:486:26:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: wasm error: unreachable
wasm stack trace:
        .$1260(i32,i32,i32,i32,i32)
        .$1406(i32,i32)
        .$1397(i32,i32,i32)
        .$1422(i32)
        .$68(i32,i32,i32)
        .$364(i32,i32)
        .$363(i32,i64,i64,i32,i32,i32) i64
        .$461(i32,i64,i64,i64,i32,i32,i32) i64
        .$454(i32,i64,i64,i32,i32,i32) i64
        .$461(i32,i64,i64,i64,i32,i32,i32) i64
        .$461(i32,i64,i64,i64,i32,i32,i32) i64
        .$461(i32,i64,i64,i64,i32,i32,i32) i64
        .$227(i32,i32,i32)
        .$1478(i32) i32
        .$1495() i32
Log file: C:\Users\muham\AppData\Local\cache\xtp\xtp-1733249505-27836.log
exit status 1

extism-js v1.2.0

PS D:\dylibso\xtp\cli\app> go run . plugin test https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm --with D:\x\extism\assertbug\dist\plugin.wasm
assert called
๐Ÿงช Testing https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm (D:\x\extism\assertbug\dist\plugin.wasm)

PASS ...... test

1/1 tests passed (completed in 42.5ยตs)

Full Repro: mhmd-azeez/assertbug

mhmd-azeez avatar Dec 03 '24 18:12 mhmd-azeez

hmmm.. maybe the rquickjs runtime doesn't have whatever inner method we're wrapping in JS in the test library.

nilslice avatar Dec 03 '24 18:12 nilslice

yeah, the host function in xtp plugin test never gets called, so the glue code breaks down somewhere

mhmd-azeez avatar Dec 03 '24 18:12 mhmd-azeez

It's odd - I don't see anything calling any JS builtin functions that would imply the runtime is missing something:

https://github.com/dylibso/xtp-test-js/blob/main/index.ts#L220-L228

nilslice avatar Dec 03 '24 18:12 nilslice

I think @bhelx had some idea what might be going wrong

mhmd-azeez avatar Dec 03 '24 18:12 mhmd-azeez

Ok, the stack says the as_big_int() call fails us https://github.com/extism/js-pdk/blob/05cecf212dd5be1db8a6633dceda4c070b8b92d1/crates/core/src/globals.rs#L482-L486

nilslice avatar Dec 03 '24 18:12 nilslice

Ok, the stack says the as_big_int() call fails us

Nice! how did you get the stack? even setting RUST_BACKTRACE didn't give me anything useful!

mhmd-azeez avatar Dec 03 '24 18:12 mhmd-azeez

It's in your initial pasted output ๐Ÿ˜† - sorry, not the wasm stack, just Rust's when the code panics

nilslice avatar Dec 03 '24 18:12 nilslice

It's in your initial pasted output ๐Ÿ˜† - sorry, not the wasm stack, just Rust's when the code panics

I have been staring at this error almost all day, and didn't see that crates/core/src/globals.rs:486:26: line ๐Ÿคฆ

mhmd-azeez avatar Dec 03 '24 18:12 mhmd-azeez

Been there, done that! It happens ๐Ÿ™‡

nilslice avatar Dec 03 '24 18:12 nilslice

I think this is because rquickjs is a little more strict about types - we have to use BigInt values for Extism pointer parameters.

It seems like the option with the least friction might be to update the js-pdk to allow BigInt or number arguments for BigInt parameters.

We could also update xtp-test-js to pass arguments as BigInt, which might be a quicker fix.

zshipko avatar Dec 05 '24 23:12 zshipko

image

mhmd-azeez avatar Dec 06 '24 07:12 mhmd-azeez