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

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

Closed
Badel2 opened this issue Jan 22, 2022 · 9 comments
Closed
Labels

Comments

@Badel2
Copy link

Badel2 commented Jan 22, 2022

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.aaakk.us.kg-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)
@Badel2 Badel2 added the bug label Jan 22, 2022
Badel2 added a commit to Badel2/slime_seed_finder that referenced this issue Jan 23, 2022
As a workaround until this issue is fixed:

rustwasm/wasm-bindgen#2776
@Badel2
Copy link
Author

Badel2 commented Jan 23, 2022

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

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

@kuviman
Copy link

kuviman commented Jan 24, 2022

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

@najtin
Copy link

najtin commented Feb 1, 2022

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

@Badel2
Copy link
Author

Badel2 commented Feb 1, 2022

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?

@taladar
Copy link

taladar commented Feb 6, 2022

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
Copy link

emilk commented Feb 8, 2023

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 😆

@Liamolucko
Copy link
Collaborator

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!

@mrchantey
Copy link

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

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

@opensourcecheemsburgers

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

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

No branches or pull requests

8 participants