@@ -316,11 +316,17 @@ fn fetch_txs_with_keychain_spks<I: Iterator<Item = Indexed<SpkWithExpectedTxids>
316
316
. collect :: < Vec < JoinHandle < Result < TxsOfSpkIndex , Error > > > > ( ) ;
317
317
318
318
if handles. is_empty ( ) {
319
+ if last_index. is_none ( ) {
320
+ return Err ( Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ;
321
+ }
319
322
break ;
320
323
}
321
324
322
325
for handle in handles {
323
- let ( index, txs, evicted) = handle. join ( ) . expect ( "thread must not panic" ) ?;
326
+ let handle_result = handle
327
+ . join ( )
328
+ . map_err ( |_| Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
329
+ let ( index, txs, evicted) = handle_result?;
324
330
last_index = Some ( index) ;
325
331
if !txs. is_empty ( ) {
326
332
last_active_index = Some ( index) ;
@@ -417,7 +423,10 @@ fn fetch_txs_with_txids<I: IntoIterator<Item = Txid>>(
417
423
}
418
424
419
425
for handle in handles {
420
- let ( txid, tx_info) = handle. join ( ) . expect ( "thread must not panic" ) ?;
426
+ let handle_result = handle
427
+ . join ( )
428
+ . map_err ( |_| Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
429
+ let ( txid, tx_info) = handle_result?;
421
430
if let Some ( tx_info) = tx_info {
422
431
if inserted_txs. insert ( txid) {
423
432
update. txs . push ( tx_info. to_tx ( ) . into ( ) ) ;
@@ -478,7 +487,10 @@ fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint>>(
478
487
}
479
488
480
489
for handle in handles {
481
- if let Some ( op_status) = handle. join ( ) . expect ( "thread must not panic" ) ? {
490
+ let handle_result = handle
491
+ . join ( )
492
+ . map_err ( |_| Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
493
+ if let Some ( op_status) = handle_result? {
482
494
let spend_txid = match op_status. txid {
483
495
Some ( txid) => txid,
484
496
None => continue ,
@@ -511,7 +523,7 @@ fn fetch_txs_with_outpoints<I: IntoIterator<Item = OutPoint>>(
511
523
#[ cfg( test) ]
512
524
#[ cfg_attr( coverage_nightly, coverage( off) ) ]
513
525
mod test {
514
- use crate :: blocking_ext:: { chain_update, fetch_latest_blocks} ;
526
+ use crate :: blocking_ext:: { chain_update, fetch_latest_blocks, Error } ;
515
527
use bdk_chain:: bitcoin;
516
528
use bdk_chain:: bitcoin:: hashes:: Hash ;
517
529
use bdk_chain:: bitcoin:: Txid ;
@@ -529,6 +541,26 @@ mod test {
529
541
} } ;
530
542
}
531
543
544
+ #[ test]
545
+ fn thread_join_panic_maps_to_error ( ) {
546
+ let handle = std:: thread:: spawn ( || -> Result < ( ) , Error > {
547
+ panic ! ( "expected panic for test coverage" ) ;
548
+ } ) ;
549
+
550
+ let res = ( || -> Result < ( ) , Error > {
551
+ let handle_result = handle
552
+ . join ( )
553
+ . map_err ( |_| Box :: new ( esplora_client:: Error :: InvalidResponse ) ) ?;
554
+ handle_result?;
555
+ Ok ( ( ) )
556
+ } ) ( ) ;
557
+
558
+ assert ! ( matches!(
559
+ * res. unwrap_err( ) ,
560
+ esplora_client:: Error :: InvalidResponse
561
+ ) ) ;
562
+ }
563
+
532
564
macro_rules! local_chain {
533
565
[ $( ( $height: expr, $block_hash: expr) ) , * ] => { {
534
566
#[ allow( unused_mut) ]
0 commit comments