Skip to main content

hashiverse_client_wasm/
wasm_try.rs

1use wasm_bindgen::prelude::*;
2pub fn anyhow_to_js(err: anyhow::Error) -> JsValue {
3    js_sys::Error::new(&format!("{:#}", err)).into()
4}
5
6#[macro_export]
7macro_rules! wasm_try {
8    ({ $($tt:tt)* }) => {{
9        (async move {
10            let result: anyhow::Result<_> = try {
11                $($tt)*
12            };
13            result
14        })
15        .await
16        .map_err($crate::wasm_try::anyhow_to_js)
17    }};
18}