From d5f47cc3f273418fdc91fefcc9703da503a54125 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 14 May 2024 08:32:20 +0200 Subject: [PATCH 1/3] fix: downgrade wasm bindgen to 0.2.78 --- Cargo.lock | 47 +++++++++++++++++++++++------------------------ Cargo.toml | 2 +- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fda9fc..64e4217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,9 +581,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -1388,9 +1388,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if", "serde", @@ -1400,24 +1400,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", + "lazy_static", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.61", + "syn 1.0.109", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.42" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ "cfg-if", "js-sys", @@ -1427,9 +1427,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1437,28 +1437,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wasm-bindgen-test" -version = "0.3.42" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" +checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e" dependencies = [ "console_error_panic_hook", "js-sys", @@ -1470,20 +1470,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.42" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" dependencies = [ "proc-macro2", "quote", - "syn 2.0.61", ] [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index e6da691..5332bf2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ enclose = "1.1.*" itertools = "0.10.*" boolinator = "2.4.*" Inflector = "0.11.*" -wasm-bindgen = { version = "=0.2.92", features = ["serde-serialize"] } +wasm-bindgen = { version = "=0.2.78", features = ["serde-serialize"] } wasm-bindgen-futures = "0.4" gloo-utils = { version = "0.2", features = ["serde"] } From 1bbaa36e40900572d65b3aafeded58ed8982271c Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 27 May 2024 10:54:24 +0300 Subject: [PATCH 2/3] fix: set Rust version to 1.77 in CI and repo Signed-off-by: Lachezar Lechev --- .github/workflows/build.yml | 2 +- .github/workflows/prerelease.yml | 2 +- .github/workflows/publish.yml | 2 +- rust-toolchain.toml | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 75d54ed..12298eb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@v4 - name: Rust setup - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.77 with: components: rustfmt, clippy targets: wasm32-unknown-unknown diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index c5a3840..f3ddf8d 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -22,7 +22,7 @@ jobs: registry-url: https://registry.npmjs.org/ - name: Rust setup - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.77 with: targets: wasm32-unknown-unknown diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b315f74..298cbf8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,7 @@ jobs: # For releasing we always use stable - name: Rust setup - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@1.77 with: targets: wasm32-unknown-unknown - uses: taiki-e/install-action@v2 diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..f0d444c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,6 @@ +[toolchain] +# 1.78 introduces a check which fails on the older +# version of wasm-bindgen, while the newest wasm-bindgen +# introduces an unknown panic when transpiled using +# wasm2js +channel = "1.77" \ No newline at end of file From f0edb336270ac6a6c1c9b9a47a1d50f53e2c89aa Mon Sep 17 00:00:00 2001 From: Lachezar Lechev Date: Mon, 27 May 2024 10:58:23 +0300 Subject: [PATCH 3/3] chore: add expect() instead of unwrap() to track panicking Signed-off-by: Lachezar Lechev --- src/env.rs | 71 +++++++++++-------- src/model/model.rs | 8 +-- src/model/serialize_catalogs_with_extra.rs | 2 +- .../serialize_continue_watching_preview.rs | 2 +- src/model/serialize_ctx.rs | 2 +- src/model/serialize_data_export.rs | 2 +- src/model/serialize_discover.rs | 7 +- src/model/serialize_installed_addons.rs | 2 +- src/model/serialize_library.rs | 2 +- src/model/serialize_local_search.rs | 2 +- src/model/serialize_meta_details.rs | 2 +- src/model/serialize_player.rs | 2 +- src/model/serialize_remote_addons.rs | 2 +- src/model/serialize_streaming_server.rs | 2 +- src/stremio_core_web.rs | 13 ++-- 15 files changed, 68 insertions(+), 53 deletions(-) diff --git a/src/env.rs b/src/env.rs index bb45f9d..3c67c47 100644 --- a/src/env.rs +++ b/src/env.rs @@ -55,7 +55,8 @@ lazy_static! { static ref VISIT_ID: String = hex::encode(WebEnv::random_buffer(10)); static ref ANALYTICS: Analytics = Default::default(); static ref PLAYER_REGEX: Regex = - Regex::new(r"^/player/([^/]*)(?:/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*))?$").unwrap(); + Regex::new(r"^/player/([^/]*)(?:/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*))?$") + .expect("Player Regex failed to build"); } #[derive(Serialize)] @@ -274,7 +275,8 @@ impl Env for WebEnv { let value = String::from_utf8_lossy(value.as_bytes()).into_owned(); headers.entry(key).or_insert_with(Vec::new).push(value); } - ::from_serde(&headers).unwrap() + ::from_serde(&headers) + .expect("WebEnv::fetch: JsValue from Headers failed to be built") }; let body = match serde_json::to_string(&body) { Ok(ref body) if body != "null" && parts.method != Method::GET => { @@ -301,7 +303,9 @@ impl Env for WebEnv { ) })?; - let resp = resp.dyn_into::().unwrap(); + let resp = resp + .dyn_into::() + .expect("WebEnv::fetch: Response into web_sys::Response failed to be built"); // status check and JSON extraction from response. let resp = if resp.status() != 200 { return Err(EnvError::Fetch(format!( @@ -311,8 +315,21 @@ impl Env for WebEnv { } else { // Response.json() to JSON::Stringify - JsFuture::from(resp.text().unwrap()) - .map_err(|error| { + JsFuture::from( + resp.text() + .expect("WebEnv::fetch: Response text failed to be retrieved"), + ) + .map_err(|error| { + EnvError::Fetch( + error + .dyn_into::() + .map(|error| String::from(error.message())) + .unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()), + ) + }) + .await + .and_then(|js_value| { + js_value.dyn_into::().map_err(|error| { EnvError::Fetch( error .dyn_into::() @@ -320,17 +337,7 @@ impl Env for WebEnv { .unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()), ) }) - .await - .and_then(|js_value| { - js_value.dyn_into::().map_err(|error| { - EnvError::Fetch( - error - .dyn_into::() - .map(|error| String::from(error.message())) - .unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()), - ) - }) - })? + })? }; response_deserialize(resp) @@ -444,7 +451,7 @@ impl Env for WebEnv { visit_id: VISIT_ID.to_owned(), path: sanitize_location_path(path), }) - .unwrap() + .expect("AnalyticsContext to JSON") } #[cfg(debug_assertions)] @@ -462,20 +469,22 @@ fn sanitize_location_path(path: &str) -> String { .unwrap_or_default(); let path = match PLAYER_REGEX.captures(url.path()) { Some(captures) => { - if captures.get(3).is_some() - && captures.get(4).is_some() - && captures.get(5).is_some() - && captures.get(6).is_some() - { - format!( - "/player/***/***/{}/{}/{}/{}", - captures.get(3).unwrap().as_str(), - captures.get(4).unwrap().as_str(), - captures.get(5).unwrap().as_str(), - captures.get(6).unwrap().as_str(), - ) - } else { - "/player/***".to_owned() + match ( + captures.get(3), + captures.get(4), + captures.get(5), + captures.get(6), + ) { + (Some(match_3), Some(match_4), Some(match_5), Some(match_6)) => { + format!( + "/player/***/***/{cap_3}/{cap_4}/{cap_5}/{cap_6}", + cap_3 = match_3.as_str(), + cap_4 = match_4.as_str(), + cap_5 = match_5.as_str(), + cap_6 = match_6.as_str(), + ) + } + _ => "/player/***".to_owned(), } } _ => url.path().to_owned(), diff --git a/src/model/model.rs b/src/model/model.rs index 2c9841e..8037898 100644 --- a/src/model/model.rs +++ b/src/model/model.rs @@ -124,9 +124,8 @@ impl WebModel { pub fn get_state(&self, field: &WebModelField) -> JsValue { match field { WebModelField::Ctx => serialize_ctx(&self.ctx), - WebModelField::AuthLink => { - ::from_serde(&self.auth_link).unwrap() - } + WebModelField::AuthLink => ::from_serde(&self.auth_link) + .expect("JsValue from AuthLink"), WebModelField::DataExport => serialize_data_export(&self.data_export), WebModelField::ContinueWatchingPreview => serialize_continue_watching_preview( &self.continue_watching_preview, @@ -158,7 +157,8 @@ impl WebModel { WebModelField::RemoteAddons => serialize_remote_addons(&self.remote_addons, &self.ctx), WebModelField::InstalledAddons => serialize_installed_addons(&self.installed_addons), WebModelField::AddonDetails => { - ::from_serde(&self.addon_details).unwrap() + ::from_serde(&self.addon_details) + .expect("JsValue from AddonDetails") } WebModelField::StreamingServer => serialize_streaming_server(&self.streaming_server), WebModelField::Player => { diff --git a/src/model/serialize_catalogs_with_extra.rs b/src/model/serialize_catalogs_with_extra.rs index 86536a3..9617902 100644 --- a/src/model/serialize_catalogs_with_extra.rs +++ b/src/model/serialize_catalogs_with_extra.rs @@ -129,5 +129,5 @@ pub fn serialize_catalogs_with_extra( ) .collect::>(), }) - .unwrap() + .expect("JsValue from model::CatalogsWithExtra") } diff --git a/src/model/serialize_continue_watching_preview.rs b/src/model/serialize_continue_watching_preview.rs index 59286b2..4545820 100644 --- a/src/model/serialize_continue_watching_preview.rs +++ b/src/model/serialize_continue_watching_preview.rs @@ -19,7 +19,7 @@ pub fn serialize_continue_watching_preview( streaming_server_url, settings, ))) - .unwrap() + .expect("JsValue from model::ContinueWatchingPreview") } mod model { diff --git a/src/model/serialize_ctx.rs b/src/model/serialize_ctx.rs index 03ffb9f..216bbf6 100644 --- a/src/model/serialize_ctx.rs +++ b/src/model/serialize_ctx.rs @@ -4,7 +4,7 @@ use wasm_bindgen::JsValue; use stremio_core::models::ctx::Ctx; pub fn serialize_ctx(ctx: &Ctx) -> JsValue { - ::from_serde(&model::Ctx::from(ctx)).unwrap() + ::from_serde(&model::Ctx::from(ctx)).expect("JsValue from Ctx") } mod model { diff --git a/src/model/serialize_data_export.rs b/src/model/serialize_data_export.rs index 71b8e36..1ce6d5e 100644 --- a/src/model/serialize_data_export.rs +++ b/src/model/serialize_data_export.rs @@ -22,5 +22,5 @@ pub fn serialize_data_export(data_export: &DataExport) -> JsValue { .as_ref() .map(|(_auth_key, loadable)| loadable), }) - .unwrap() + .expect("JsValue from model::DataExport") } diff --git a/src/model/serialize_discover.rs b/src/model/serialize_discover.rs index 590c4a0..beb4631 100644 --- a/src/model/serialize_discover.rs +++ b/src/model/serialize_discover.rs @@ -167,7 +167,10 @@ pub fn serialize_discover( next_page: discover.selectable.next_page.is_some(), }, catalog: (!discover.catalog.is_empty()).as_option().map(|_| { - let first_page = discover.catalog.first().unwrap(); + let first_page = discover + .catalog + .first() + .expect("discover catalog first page"); model::ResourceLoadable { content: match &first_page.content { Some(Loadable::Ready(_)) => Loadable::Ready( @@ -228,5 +231,5 @@ pub fn serialize_discover( } }), }) - .unwrap() + .expect("JsValue from Discover model::CatalogWithFilters") } diff --git a/src/model/serialize_installed_addons.rs b/src/model/serialize_installed_addons.rs index e974791..4893ace 100644 --- a/src/model/serialize_installed_addons.rs +++ b/src/model/serialize_installed_addons.rs @@ -76,5 +76,5 @@ pub fn serialize_installed_addons(installed_addons: &InstalledAddonsWithFilters) }) .collect(), }) - .unwrap() + .expect("JsValue from model::InstalledAddonsWithFilters") } diff --git a/src/model/serialize_library.rs b/src/model/serialize_library.rs index 44e7e88..d650cf8 100644 --- a/src/model/serialize_library.rs +++ b/src/model/serialize_library.rs @@ -133,5 +133,5 @@ pub fn serialize_library( }) .collect(), }) - .unwrap() + .expect("JsValue from model::LibraryWithFilters") } diff --git a/src/model/serialize_local_search.rs b/src/model/serialize_local_search.rs index 15f391e..d7eca48 100644 --- a/src/model/serialize_local_search.rs +++ b/src/model/serialize_local_search.rs @@ -39,5 +39,5 @@ pub fn serialize_local_search(local_search: &LocalSearch) -> JsValue { .unique_by(|i| i.query) .collect(), }) - .unwrap() + .expect("JsValue from model::LocalSearch") } diff --git a/src/model/serialize_meta_details.rs b/src/model/serialize_meta_details.rs index 4d0e0c5..cf43fab 100644 --- a/src/model/serialize_meta_details.rs +++ b/src/model/serialize_meta_details.rs @@ -376,5 +376,5 @@ pub fn serialize_meta_details( .unwrap_or_else(|| meta_item.preview.name.to_owned()) }), }) - .unwrap() + .expect("JsValue from model::MetaDetails") } diff --git a/src/model/serialize_player.rs b/src/model/serialize_player.rs index 9311ea1..480f16b 100644 --- a/src/model/serialize_player.rs +++ b/src/model/serialize_player.rs @@ -304,5 +304,5 @@ pub fn serialize_player(player: &Player, ctx: &Ctx, streaming_server: &Streaming }, }), }) - .unwrap() + .expect("JsValue from model::Player") } diff --git a/src/model/serialize_remote_addons.rs b/src/model/serialize_remote_addons.rs index 14b9ff3..6611410 100644 --- a/src/model/serialize_remote_addons.rs +++ b/src/model/serialize_remote_addons.rs @@ -107,5 +107,5 @@ pub fn serialize_remote_addons( }, }), }) - .unwrap() + .expect("JsValue from model::CatalogWithFilters") } diff --git a/src/model/serialize_streaming_server.rs b/src/model/serialize_streaming_server.rs index cb78a6d..c28cb39 100644 --- a/src/model/serialize_streaming_server.rs +++ b/src/model/serialize_streaming_server.rs @@ -53,5 +53,5 @@ pub fn serialize_streaming_server(streaming_server: &StreamingServer) -> JsValue }), statistics: streaming_server.statistics.as_ref(), }) - .unwrap() + .expect("JsValue from model::StreamingServer") } diff --git a/src/stremio_core_web.rs b/src/stremio_core_web.rs index 59553cc..1688a8e 100644 --- a/src/stremio_core_web.rs +++ b/src/stremio_core_web.rs @@ -133,7 +133,7 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa )); }; emit_to_ui - .call1(&JsValue::NULL, &::from_serde(&event).unwrap()) + .call1(&JsValue::NULL, &::from_serde(&event).expect("Event handler: JsValue from Event")) .expect("emit event failed"); future::ready(()) })); @@ -144,13 +144,14 @@ pub async fn initialize_runtime(emit_to_ui: js_sys::Function) -> Result<(), JsVa Err(error) => { *RUNTIME.write().expect("runtime write failed") = Some(Loadable::Err(error.to_owned())); - Err(::from_serde(&error).unwrap()) + Err(::from_serde(&error) + .expect("Storage: JsValue from Event")) } } } Err(error) => { *RUNTIME.write().expect("runtime write failed") = Some(Loadable::Err(error.to_owned())); - Err(::from_serde(&error).unwrap()) + Err(::from_serde(&error).expect("JsValue from Event")) } } } @@ -165,7 +166,7 @@ pub fn get_debug_state() -> JsValue { .as_ref() .expect("runtime is not ready"); let model = runtime.model().expect("model read failed"); - ::from_serde(&*model).unwrap() + ::from_serde(&*model).expect("JsValue from WebModel") } #[wasm_bindgen] @@ -230,7 +231,9 @@ pub fn analytics(event: JsValue, location_hash: JsValue) { pub fn decode_stream(stream: JsValue) -> JsValue { let stream = stream.as_string().map(Stream::decode); match stream { - Some(Ok(stream)) => ::from_serde(&stream).unwrap(), + Some(Ok(stream)) => { + ::from_serde(&stream).expect("JsValue from Stream") + } _ => JsValue::NULL, } }