rustwasm/wasm-bindgen

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0'

Badel2 opened this issue ยท 9 comments

Describe the Bug

I am unable to use wasm-bindgen. It was working fine with wasm-bindgen 0.2.78, stopped working in wasm-bindgen 0.2.79

Steps to Reproduce

git clone https://github.com/Badel2/slime_seed_finder
cd slime_seed_finder
git checkout ae37e3f6b0aa0b90d0e8c15c97b88aab204ca7d2
./ci/install_wasm_bindgen.sh
./ci/build_demo.sh
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/bdl/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-cli-support-0.2.79/src/descriptor.rs:208:15
stack backtrace:
   0: rust_begin_unwind
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_bounds_check
             at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:75:5
   3: wasm_bindgen_cli_support::descriptor::Descriptor::_decode
   4: wasm_bindgen_cli_support::descriptor::Descriptor::_decode
   5: wasm_bindgen_cli_support::descriptor::Descriptor::_decode
   6: wasm_bindgen_cli_support::descriptor::Function::decode
   7: wasm_bindgen_cli_support::descriptor::Descriptor::_decode
   8: wasm_bindgen_cli_support::descriptors::execute
   9: wasm_bindgen_cli_support::Bindgen::generate_output
  10: wasm_bindgen_cli_support::Bindgen::generate
  11: wasm_bindgen::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
$ rustc --version
rustc 1.58.1 (db9d1b20b 2022-01-20)

As a workaround, I decided to use the old version until this is fixed:

cargo install -f wasm-bindgen-cli --version 0.2.78

Hit this too. In my case wasm-bindgen-cli was version 0.2.78 and wasm-bindgen dependency was 0.2.79.

This looks like #2679 happening again, the correct workaround is using same versions, as using 0.2.79 for both works as well as 0.2.78 for both worked before

So in your case @Badel2 I see wasm-bindgen 0.2.78 in Cargo.lock so, you could just cargo update

i am using trunk and just running cargo update didn't do the job. I also had to delete the Cargo.lock file.

Thank you @kuviman, I forgot that there is also a wasm-bindgen in the Cargo.lock.

Perhaps to avoid the same issue in the future, the wasm-bindgen binary could check the version in Cargo.lock and show an error if the versions don't match?

I had the same issue and in my case I was using a workspace for my backend and frontend crates and the Cargo.lock in the workspace had the correct versions but there was another Cargo.lock in the frontend crate dir that had the wrong version. Once I deleted the latter everything worked.

emilk commented

I just hit this too after an update to v0.2.84. I believe for me too this is because of a mismatch of the wasm-bindgen and wasm-bindgen-cli. I feel this error message could be improved ๐Ÿ˜†

This should be fixed by #3205 for any future updates. It's still possible for this to come up when going from 0.2.83 -> 0.2.84 if the library is the one that gets updated, since the fix is only in v0.2.84 of the CLI, but any future updates should give a proper error message like this:

it looks like the Rust project used to create this wasm file was linked against
version of wasm-bindgen that uses a different bindgen format than this binary:

  rust wasm file schema version: 0.2.83
     this binary schema version: 0.2.84

Currently the bindgen format is unstable enough that these two schema versions
must exactly match. You can accomplish this by either updating the wasm-bindgen
dependency or this binary.

You should be able to update the wasm-bindgen dependency with:

    cargo update -p wasm-bindgen

or you can update the binary with

    cargo install -f wasm-bindgen-cli

if this warning fails to go away though and you're not sure what to do feel free
to open an issue at https://github.com/rustwasm/wasm-bindgen/issues!

Yes I can confirm that updating the cli fixed the issue:

cargo install -f wasm-bindgen-cli --version 0.2.84

For trunk users, make sure the wasm-bindgen versions match in Trunk.toml and Cargo.toml.