@@ -44,6 +44,18 @@ enum QueryResult {
4444 Poisoned ,
4545}
4646
47+ impl QueryResult {
48+ /// Unwraps the query job expecting that it has started.
49+ fn expect_job ( self ) -> QueryJob {
50+ match self {
51+ Self :: Started ( job) => job,
52+ Self :: Poisoned => {
53+ panic ! ( "job for query failed to start and was poisoned" )
54+ }
55+ }
56+ }
57+ }
58+
4759impl < K > QueryState < K >
4860where
4961 K : Eq + Hash + Copy + Debug ,
@@ -169,10 +181,7 @@ where
169181
170182 let job = {
171183 let mut lock = state. active . lock_shard_by_value ( & key) ;
172- match lock. remove ( & key) . unwrap ( ) {
173- QueryResult :: Started ( job) => job,
174- QueryResult :: Poisoned => panic ! ( ) ,
175- }
184+ lock. remove ( & key) . unwrap ( ) . expect_job ( )
176185 } ;
177186
178187 job. signal_complete ( ) ;
@@ -190,10 +199,8 @@ where
190199 let state = self . state ;
191200 let job = {
192201 let mut shard = state. active . lock_shard_by_value ( & self . key ) ;
193- let job = match shard. remove ( & self . key ) . unwrap ( ) {
194- QueryResult :: Started ( job) => job,
195- QueryResult :: Poisoned => panic ! ( ) ,
196- } ;
202+ let job = shard. remove ( & self . key ) . unwrap ( ) . expect_job ( ) ;
203+
197204 shard. insert ( self . key , QueryResult :: Poisoned ) ;
198205 job
199206 } ;
@@ -277,11 +284,14 @@ where
277284 // We didn't find the query result in the query cache. Check if it was
278285 // poisoned due to a panic instead.
279286 let lock = query. query_state ( qcx) . active . get_shard_by_value ( & key) . lock ( ) ;
287+
280288 match lock. get ( & key) {
281- // The query we waited on panicked. Continue unwinding here.
282- Some ( QueryResult :: Poisoned ) => FatalError . raise ( ) ,
289+ Some ( QueryResult :: Poisoned ) => {
290+ panic ! ( "query '{}' not cached due to poisoning" , query. name( ) )
291+ }
283292 _ => panic ! (
284- "query result must in the cache or the query must be poisoned after a wait"
293+ "query '{}' result must be in the cache or the query must be poisoned after a wait" ,
294+ query. name( )
285295 ) ,
286296 }
287297 } )
0 commit comments