File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " tauri " : patch:enhance
3
+ ---
4
+
5
+ Enhance panic message when fetching unmanaged state.
Original file line number Diff line number Diff line change @@ -738,11 +738,12 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
738
738
where
739
739
T : Send + Sync + ' static ,
740
740
{
741
- self
742
- . manager ( )
743
- . state
744
- . try_get ( )
745
- . expect ( "state() called before manage() for given type" )
741
+ self . manager ( ) . state . try_get ( ) . unwrap_or_else ( || {
742
+ panic ! (
743
+ "state() called before manage() for {}" ,
744
+ std:: any:: type_name:: <T >( )
745
+ )
746
+ } )
746
747
}
747
748
748
749
/// Attempts to retrieve the managed state for the type `T`.
Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ impl StateManager {
153
153
pub fn get < T : Send + Sync + ' static > ( & self ) -> State < ' _ , T > {
154
154
self
155
155
. try_get ( )
156
- . expect ( "state: get() when given type is not managed" )
156
+ . unwrap_or_else ( || panic ! ( "state not found for type {}" , std :: any :: type_name :: < T > ( ) ) )
157
157
}
158
158
159
159
/// Gets the state associated with the specified type.
@@ -191,6 +191,13 @@ mod tests {
191
191
}
192
192
}
193
193
194
+ #[ test]
195
+ #[ should_panic( expected = "state not found for type core::option::Option<alloc::string::String>" ) ]
196
+ fn get_panics ( ) {
197
+ let state = StateManager :: new ( ) ;
198
+ state. get :: < Option < String > > ( ) ;
199
+ }
200
+
194
201
#[ test]
195
202
fn simple_set_get ( ) {
196
203
let state = StateManager :: new ( ) ;
You can’t perform that action at this time.
0 commit comments