strawmanning
rustc is smart:
error: literal out of range for `usize`
|
79 | data.resize(10_000_000_000, 42_u8);
| ^^^^^^^^^^^^^^
|
= note: `#[deny(overflowing_literals)]` on by default
= note: the literal `10_000_000_000` does not fit into the type `usize` whose range is `0..=4294967295`
steelmanning
pub struct T {
data: [u8; 100],}
let mut data = Vec::<T>::new();
data.reserve(1_000_000_000);
Here are the two errors I am getting in Chrome dev console right now:
client_w.js:474 panicked at 'capacity overflow', library/alloc/src/raw_vec.rs:517:5
Stack:
Error
at imports.wbg.__wbg_new_693216e109162396 (http://localhost:8080/client_w.js:477:17)
at console_error_panic_hook::Error::new::h8668ab84cb67189b (http://localhost:8080/client_w_bg.wasm:wasm-function[15376]:0x41a242)
at console_error_panic_hook::hook_impl::hbfeb05050ef0e2aa (http://localhost:8080/client_w_bg.wasm:wasm-function[1791]:0x242799)
at console_error_panic_hook::hook::h6a9927c1f0888f41 (http://localhost:8080/client_w_bg.wasm:wasm-function[16491]:0x429d6d)
at core::ops::function::Fn::call::h167ccd9c6a07f6c8 (http://localhost:8080/client_w_bg.wasm:wasm-function[14229]:0x408382)
at std::panicking::rust_panic_with_hook::h1c368a27f9b0afe1 (http://localhost:8080/client_w_bg.wasm:wasm-function[3903]:0x2e23f7)
at std::panicking::begin_panic_handler::{{closure}}::h8e1f8b682ca33009 (http://localhost:8080/client_w_bg.wasm:wasm-function[6135]:0x348636)
at std::sys_common::backtrace::__rust_end_short_backtrace::h7f7da41799766719 (http://localhost:8080/client_w_bg.wasm:wasm-function[19727]:0x44a9f1)
at rust_begin_unwind (http://localhost:8080/client_w_bg.wasm:wasm-function[15646]:0x41e18f)
at core::panicking::panic_fmt::hcdb13a4b2416cf82 (http://localhost:8080/client_w_bg.wasm:wasm-function[16345]:0x427de3)
client_w_bg.wasm:0x44b77b Uncaught (in promise) RuntimeError: unreachable
at __rust_start_panic (client_w_bg.wasm:0x44b77b)
at rust_panic (client_w_bg.wasm:0x43fc20)
at std::panicking::rust_panic_with_hook::h1c368a27f9b0afe1 (client_w_bg.wasm:0x2e2424)
at std::panicking::begin_panic_handler::{{closure}}::h8e1f8b682ca33009 (client_w_bg.wasm:0x348636)
at std::sys_common::backtrace::__rust_end_short_backtrace::h7f7da41799766719 (client_w_bg.wasm:0x44a9f1)
at rust_begin_unwind (client_w_bg.wasm:0x41e18f)
at core::panicking::panic_fmt::hcdb13a4b2416cf82 (client_w_bg.wasm:0x427de3)
at alloc::raw_vec::capacity_overflow::h9e24c4d5bbf80bc3 (client_w_bg.wasm:0x427da3)
at alloc::raw_vec::handle_reserve::h3bf48243ce6ec1b2 (client_w_bg.wasm:0x319568)
at alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle::h96b1e49ef4ba0aad (client_w_bg.wasm:0x39431a)
analysis
The first one "panicked at 'capacity overflow'" definitely looks like a Rust exception.
I am not clear if the second "Uncaught (in promis) RuntimeError: unreachable" is a Rust or a JS exception.
For comparison, if I just type
throw "blah"
into the Chrome dev console, the response is:
VM304:1 Uncaught blah
(anonymous) @ VM304:1
failing to catch it in JS land
I have the following JS fragment:
import init, * as wasm from "./client_w.js";
try {
await init();
var t2 = await wasm.Rust_Util.start_th_router()
} catch (e) {
console.log("JS caught error: ", e);
}
init
is the JS function show in previous post, generated by the cargo build process
RustUtil is a Rust struct that looks like:
#[wasm_bindgen]
impl Rust_Util {
pub async fn start_th_router() {
Th_Router::start().await}
...
}
(Th_Router::start ends up doing the massive Vec).
I'm not sure why JS is not catching the exception right now. Possibly something to do with async (pure guess, no hard evidence).