Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panicked with 'called Result::unwrap() on an Err value: Custom("invalid value: integer 4984270261285729579, expected usize")' after compiling to WebAssembly and running on nodejs #277

Closed
JohnGouwar opened this issue Jan 18, 2022 · 2 comments

Comments

@JohnGouwar
Copy link

OS: Ubuntu 20.04 64 bit

Steps to reproduce bug:
0) Follow Quickstart guide from grmtools book.

  1. Edit the Cargo.toml in the following way
[lib]
crate-type = ["cdylib"]

[build-dependencies]
cfgrammar = "0.11"
lrlex = "0.11"
lrpar = "0.11"

[dependencies]
cfgrammar = "0.11"
lrlex = "0.11"
lrpar = "0.11"
wasm-bindgen = "0.2"
console_error_panic_hook = "*"
  1. Edit parse function in the following way in src/lib.rs
#[wasm_bindgen]
pub fn parse(string: &str) -> u64 { 
    console_error_panic_hook::set_once();
    let lexerdef = calc_l::lexerdef();
    let lexer = lexerdef.lexer(string);
    // Pass the lexer to the parser and lex and parse the input.
    let (res, _) = calc_y::parse(&lexer);
    match res {
        Some(r) => r.unwrap(),
        _ => panic!("Failed to parse expression"),
    }
}
  1. Compile using `wasm-pack build --target nodejs
  2. Link the package to a node project
  3. Run the following script using node
const calc = require("calc");
console.log(calc.parse("2 + 3"))

My initial conjecture is that there is a cast between u64 and usize somewhere, which does not work with the Wasm architecture.

@ltratt
Copy link
Member

ltratt commented Jan 18, 2022

There isn't explicit support for wasm (if someone wants to add it, I'd accept a PR) but issue #124 may give you a hack to get around the problem?

@JohnGouwar
Copy link
Author

Ah, that's fair. I see that others have an issue from compiling on a 64 bit architecture, I'll try building with 32bit container. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants