File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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> {
738738 where
739739 T : Send + Sync + ' static ,
740740 {
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+ } )
746747 }
747748
748749 /// 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 {
153153 pub fn get < T : Send + Sync + ' static > ( & self ) -> State < ' _ , T > {
154154 self
155155 . 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 > ( ) ) )
157157 }
158158
159159 /// Gets the state associated with the specified type.
@@ -191,6 +191,13 @@ mod tests {
191191 }
192192 }
193193
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+
194201 #[ test]
195202 fn simple_set_get ( ) {
196203 let state = StateManager :: new ( ) ;
You can’t perform that action at this time.
0 commit comments