Skip to content

Commit ca7f025

Browse files
authored
fix(core): return an error when accessing unmanaged state in command (#11958)
closes #11949
1 parent 17bcec8 commit ca7f025

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

.changes/unmanaged-state-command.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": "patch:bug"
3+
---
4+
5+
Fix panic when invoking a command with an unmanaged state, an error will be returned instead.

Cargo.lock

+19-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/state.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ impl<T: Send + Sync + std::fmt::Debug> std::fmt::Debug for State<'_, T> {
6060
impl<'r, 'de: 'r, T: Send + Sync + 'static, R: Runtime> CommandArg<'de, R> for State<'r, T> {
6161
/// Grabs the [`State`] from the [`CommandItem`]. This will never fail.
6262
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError> {
63-
Ok(command.message.state_ref().try_get().unwrap_or_else(|| {
64-
panic!(
63+
command.message.state_ref().try_get().ok_or_else(|| {
64+
InvokeError::from_anyhow(anyhow::anyhow!(
6565
"state not managed for field `{}` on command `{}`. You must call `.manage()` before using this command",
6666
command.key, command.name
67-
)
68-
}))
67+
))
68+
})
6969
}
7070
}
7171

0 commit comments

Comments
 (0)