@@ -44,6 +44,18 @@ enum QueryResult {
44
44
Poisoned ,
45
45
}
46
46
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
+
47
59
impl < K > QueryState < K >
48
60
where
49
61
K : Eq + Hash + Copy + Debug ,
@@ -169,10 +181,7 @@ where
169
181
170
182
let job = {
171
183
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 ( )
176
185
} ;
177
186
178
187
job. signal_complete ( ) ;
@@ -190,10 +199,8 @@ where
190
199
let state = self . state ;
191
200
let job = {
192
201
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
+
197
204
shard. insert ( self . key , QueryResult :: Poisoned ) ;
198
205
job
199
206
} ;
@@ -277,11 +284,14 @@ where
277
284
// We didn't find the query result in the query cache. Check if it was
278
285
// poisoned due to a panic instead.
279
286
let lock = query. query_state ( qcx) . active . get_shard_by_value ( & key) . lock ( ) ;
287
+
280
288
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
+ }
283
292
_ => 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( )
285
295
) ,
286
296
}
287
297
} )
0 commit comments