From ca7f025fd8666f8fce6894bb5e16cf2d4fc81e0c Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 12 Dec 2024 23:05:32 +0200 Subject: [PATCH] fix(core): return an error when accessing unmanaged state in command (#11958) closes #11949 --- .changes/unmanaged-state-command.md | 5 ++++ Cargo.lock | 38 ++++++++++++++--------------- crates/tauri/src/state.rs | 8 +++--- 3 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 .changes/unmanaged-state-command.md diff --git a/.changes/unmanaged-state-command.md b/.changes/unmanaged-state-command.md new file mode 100644 index 000000000000..fca4ecb6fc2f --- /dev/null +++ b/.changes/unmanaged-state-command.md @@ -0,0 +1,5 @@ +--- +"tauri": "patch:bug" +--- + +Fix panic when invoking a command with an unmanaged state, an error will be returned instead. diff --git a/Cargo.lock b/Cargo.lock index 173a44c92ff0..a5acd18ef2d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4858,7 +4858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -6647,9 +6647,9 @@ dependencies = [ [[package]] name = "png" -version = "0.17.15" +version = "0.17.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67582bd5b65bdff614270e2ea89a1cf15bef71245cc1e5f7ea126977144211d" +checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -7978,9 +7978,9 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.216" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] @@ -8042,9 +8042,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", @@ -9042,7 +9042,7 @@ dependencies = [ "tauri-runtime", "tauri-runtime-wry", "tauri-utils 2.1.0", - "thiserror 2.0.6", + "thiserror 2.0.4", "tokio", "tracing", "tray-icon", @@ -9110,7 +9110,7 @@ dependencies = [ "tauri-macos-sign", "tauri-utils 2.1.0", "tempfile", - "thiserror 2.0.6", + "thiserror 2.0.4", "time", "ureq", "url", @@ -9230,7 +9230,7 @@ dependencies = [ "sha2", "syn 2.0.90", "tauri-utils 2.1.0", - "thiserror 2.0.6", + "thiserror 2.0.4", "time", "url", "uuid", @@ -9369,7 +9369,7 @@ dependencies = [ "serde", "tauri", "tauri-plugin 2.0.3", - "thiserror 2.0.6", + "thiserror 2.0.4", ] [[package]] @@ -9384,7 +9384,7 @@ dependencies = [ "serde", "serde_json", "tauri-utils 2.1.0", - "thiserror 2.0.6", + "thiserror 2.0.4", "url", "windows", ] @@ -9536,7 +9536,7 @@ dependencies = [ "serial_test", "serialize-to-javascript", "swift-rs", - "thiserror 2.0.6", + "thiserror 2.0.4", "toml 0.8.19", "url", "urlpattern", @@ -9637,11 +9637,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.6" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fec2a1820ebd077e2b90c4df007bebf344cd394098a13c563957d0afc83ea47" +checksum = "2f49a1853cf82743e3b7950f77e0f4d622ca36cf4317cba00c767838bac8d490" dependencies = [ - "thiserror-impl 2.0.6", + "thiserror-impl 2.0.4", ] [[package]] @@ -9657,9 +9657,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.6" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d65750cab40f4ff1929fb1ba509e9914eb756131cef4210da8d5d700d26f6312" +checksum = "8381894bb3efe0c4acac3ded651301ceee58a15d47c2e34885ed1908ad667061" dependencies = [ "proc-macro2", "quote", @@ -10801,7 +10801,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/crates/tauri/src/state.rs b/crates/tauri/src/state.rs index 8175e62c7272..2f1092e6ce02 100644 --- a/crates/tauri/src/state.rs +++ b/crates/tauri/src/state.rs @@ -60,12 +60,12 @@ impl std::fmt::Debug for State<'_, T> { impl<'r, 'de: 'r, T: Send + Sync + 'static, R: Runtime> CommandArg<'de, R> for State<'r, T> { /// Grabs the [`State`] from the [`CommandItem`]. This will never fail. fn from_command(command: CommandItem<'de, R>) -> Result { - Ok(command.message.state_ref().try_get().unwrap_or_else(|| { - panic!( + command.message.state_ref().try_get().ok_or_else(|| { + InvokeError::from_anyhow(anyhow::anyhow!( "state not managed for field `{}` on command `{}`. You must call `.manage()` before using this command", command.key, command.name - ) - })) + )) + }) } }