Skip to content

Commit

Permalink
fix(core): return an error when accessing unmanaged state in command (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Dec 12, 2024
1 parent 17bcec8 commit ca7f025
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changes/unmanaged-state-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:bug"
---

Fix panic when invoking a command with an unmanaged state, an error will be returned instead.
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/tauri/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ impl<T: Send + Sync + std::fmt::Debug> 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<Self, InvokeError> {
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
)
}))
))
})
}
}

Expand Down

0 comments on commit ca7f025

Please sign in to comment.