Skip to content

Commit

Permalink
chore(core): improve state API panic error message, closes tauri-ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 9, 2021
1 parent 1ecb865 commit e853946
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/state-get-panic-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Improve panic message for accessing the `state` API before calling `manage`.
6 changes: 5 additions & 1 deletion core/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
where
T: Send + Sync + 'static,
{
self.manager().inner.state.get()
self.manager().inner.state.try_get().unwrap_or_else(|| {
panic!(
"Failed to access managed state. You must call the `manage` API before reading a State."
)
})
}

/// Tries to get the managed state for the type `T`. Returns `None` if the type is not managed.
Expand Down

0 comments on commit e853946

Please sign in to comment.