Skip to content

Commit 25baed1

Browse files
committed
chore: Apply Clippy lint expect_fun_call
1 parent a195736 commit 25baed1

File tree

11 files changed

+49
-81
lines changed

11 files changed

+49
-81
lines changed

stackslib/src/burnchains/bitcoin/indexer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ impl BitcoinIndexer {
234234
true,
235235
false,
236236
)
237-
.expect(&format!(
238-
"Failed to open {:?}",
239-
working_dir_path.to_str().unwrap()
240-
));
237+
.unwrap_or_else(|_| panic!("Failed to open {:?}", working_dir_path.to_str().unwrap()));
241238

242239
BitcoinIndexer {
243240
config: BitcoinIndexerConfig::default_regtest(

stackslib/src/burnchains/tests/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,7 @@ impl TestBurnchainBlock {
439439
// prove on the last-ever sortition's hash to produce the new seed
440440
let proof = miner
441441
.make_proof(&leader_key.public_key, &last_snapshot.sortition_hash)
442-
.expect(&format!(
443-
"FATAL: no private key for {}",
444-
leader_key.public_key.to_hex()
445-
));
442+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", leader_key.public_key));
446443

447444
VRFSeed::from_proof(&proof)
448445
});
@@ -658,10 +655,12 @@ impl TestBurnchainBlock {
658655
let parent_hdr = indexer
659656
.read_burnchain_header(self.block_height.saturating_sub(1))
660657
.unwrap()
661-
.expect(&format!(
662-
"BUG: could not read block at height {}",
663-
self.block_height.saturating_sub(1)
664-
));
658+
.unwrap_or_else(|| {
659+
panic!(
660+
"BUG: could not read block at height {}",
661+
self.block_height.saturating_sub(1)
662+
)
663+
});
665664

666665
let now = BURNCHAIN_TEST_BLOCK_TIME;
667666
let block_hash = BurnchainHeaderHash::from_bitcoin_hash(

stackslib/src/chainstate/nakamoto/tests/node.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl TestPeer<'_> {
13441344
);
13451345
}
13461346
Err(e) => {
1347-
panic!("Failure fetching recipient set: {:?}", e);
1347+
panic!("Failure fetching recipient set: {e:?}");
13481348
}
13491349
};
13501350

@@ -1368,16 +1368,11 @@ impl TestPeer<'_> {
13681368
let proof = self
13691369
.miner
13701370
.make_proof(&miner_key.public_key, &tip.sortition_hash)
1371-
.expect(&format!(
1372-
"FATAL: no private key for {}",
1373-
miner_key.public_key.to_hex()
1374-
));
1371+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", miner_key.public_key));
13751372
self.sortdb = Some(sortdb);
13761373
debug!(
1377-
"VRF proof made from {} over {}: {}",
1378-
&miner_key.public_key.to_hex(),
1379-
&tip.sortition_hash,
1380-
&proof.to_hex()
1374+
"VRF proof made from {:?} over {}: {proof:?}",
1375+
miner_key.public_key, &tip.sortition_hash
13811376
);
13821377
proof
13831378
}

stackslib/src/chainstate/stacks/boot/pox_2_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ pub fn check_stacking_state_invariants(
334334
.burn_header_height;
335335

336336
let stacking_state_entry = get_stacking_state_pox(peer, tip, stacker, active_pox_contract)
337-
.expect(&format!(
338-
"Invariant violated: reward-cycle entry has stacker field set, but not present in stacker-state (pox_contract = {})",
339-
active_pox_contract,
340-
))
337+
.unwrap_or_else(|| panic!("Invariant violated: reward-cycle entry has stacker field set, but not present in stacker-state (pox_contract = {active_pox_contract})"))
341338
.expect_tuple().unwrap();
342339
let first_cycle = stacking_state_entry
343340
.get("first-reward-cycle")

stackslib/src/chainstate/stacks/boot/pox_4_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10265,7 +10265,7 @@ fn test_scenario_five(use_nakamoto: bool) {
1026510265
for (idx, (stacker, stacker_lock_period)) in davids_stackers.iter().enumerate() {
1026610266
let (pox_address, first_reward_cycle, lock_period, _indices) =
1026710267
get_stacker_info_pox_4(&mut peer, &stacker.principal)
10268-
.expect(format!("Failed to find stacker {}", idx).as_str());
10268+
.unwrap_or_else(|| panic!("Failed to find stacker {idx}"));
1026910269
assert_eq!(first_reward_cycle, reward_cycle);
1027010270
assert_eq!(pox_address, david.pox_address);
1027110271
assert_eq!(lock_period, *stacker_lock_period);
@@ -10274,7 +10274,7 @@ fn test_scenario_five(use_nakamoto: bool) {
1027410274
for (idx, (stacker, stacker_lock_period)) in eves_stackers.iter().enumerate() {
1027510275
let (pox_address, first_reward_cycle, lock_period, _indices) =
1027610276
get_stacker_info_pox_4(&mut peer, &stacker.principal)
10277-
.expect(format!("Failed to find stacker {}", idx).as_str());
10277+
.unwrap_or_else(|| panic!("Failed to find stacker {idx}"));
1027810278
assert_eq!(first_reward_cycle, reward_cycle);
1027910279
assert_eq!(pox_address, eve.pox_address);
1028010280
assert_eq!(lock_period, *stacker_lock_period);

stackslib/src/chainstate/stacks/tests/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,7 @@ impl TestStacksNode {
619619
&miner_key.public_key,
620620
&burn_block.parent_snapshot.sortition_hash,
621621
)
622-
.expect(&format!(
623-
"FATAL: no private key for {}",
624-
miner_key.public_key.to_hex()
625-
));
622+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", miner_key.public_key));
626623

627624
let (builder, parent_block_snapshot_opt) = match parent_stacks_block {
628625
None => {

stackslib/src/net/download/nakamoto/tenure.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,12 @@ impl TenureStartEnd {
345345
rc,
346346
pox_constants
347347
.block_height_to_reward_cycle(first_burn_height, wt_start.burn_height)
348-
.expect(&format!(
349-
"FATAL: tenure from before system start ({} <= {})",
350-
wt_start.burn_height, first_burn_height
351-
)),
348+
.unwrap_or_else(|| {
349+
panic!(
350+
"FATAL: tenure from before system start ({} <= {first_burn_height})",
351+
wt_start.burn_height
352+
)
353+
}),
352354
wt.processed,
353355
);
354356
tenure_start_end.fetch_end_block = true;

stackslib/src/net/httpcore.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,9 @@ impl StacksHttp {
10141014
pub fn set_response_handler(&mut self, request_verb: &str, request_path: &str) {
10151015
let handler_index = self
10161016
.find_response_handler(request_verb, request_path)
1017-
.expect(&format!(
1018-
"FATAL: could not find handler for '{}' '{}'",
1019-
request_verb, request_path
1020-
));
1017+
.unwrap_or_else(|| {
1018+
panic!("FATAL: could not find handler for '{request_verb}' '{request_path}'")
1019+
});
10211020
self.request_handler_index = Some(handler_index);
10221021
}
10231022

stackslib/src/net/mod.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,18 +4257,15 @@ pub mod test {
42574257
let mut stacks_node = self.stacks_node.take().unwrap();
42584258

42594259
let parent_block_opt = stacks_node.get_last_anchored_block(&self.miner);
4260-
let parent_sortition_opt = match parent_block_opt.as_ref() {
4261-
Some(parent_block) => {
4262-
let ic = sortdb.index_conn();
4263-
SortitionDB::get_block_snapshot_for_winning_stacks_block(
4264-
&ic,
4265-
&tip.sortition_id,
4266-
&parent_block.block_hash(),
4267-
)
4268-
.unwrap()
4269-
}
4270-
None => None,
4271-
};
4260+
let parent_sortition_opt = parent_block_opt.as_ref().and_then(|parent_block| {
4261+
let ic = sortdb.index_conn();
4262+
SortitionDB::get_block_snapshot_for_winning_stacks_block(
4263+
&ic,
4264+
&tip.sortition_id,
4265+
&parent_block.block_hash(),
4266+
)
4267+
.unwrap()
4268+
});
42724269

42734270
let parent_microblock_header_opt =
42744271
get_last_microblock_header(&stacks_node, &self.miner, parent_block_opt.as_ref());
@@ -4284,10 +4281,7 @@ pub mod test {
42844281
&last_key.public_key,
42854282
&burn_block.parent_snapshot.sortition_hash,
42864283
)
4287-
.expect(&format!(
4288-
"FATAL: no private key for {}",
4289-
last_key.public_key.to_hex()
4290-
));
4284+
.unwrap_or_else(|| panic!("FATAL: no private key for {:?}", last_key.public_key));
42914285

42924286
let (stacks_block, microblocks) = tenure_builder(
42934287
&mut self.miner,
@@ -4547,10 +4541,9 @@ pub mod test {
45474541
self.config
45484542
.burnchain
45494543
.block_height_to_reward_cycle(block_height)
4550-
.expect(&format!(
4551-
"Failed to get reward cycle for block height {}",
4552-
block_height
4553-
))
4544+
.unwrap_or_else(|| {
4545+
panic!("Failed to get reward cycle for block height {block_height}")
4546+
})
45544547
}
45554548

45564549
/// Verify that the sortition DB migration into Nakamoto worked correctly.

stackslib/src/net/stackerdb/tests/config.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,25 +525,24 @@ fn test_valid_and_invalid_stackerdb_configs() {
525525
)
526526
.unwrap()
527527
.into(),
528-
ContractName::try_from(format!("test-{}", i)).unwrap(),
528+
ContractName::try_from(format!("test-{i}")).unwrap(),
529529
);
530530
peer.with_db_state(|sortdb, chainstate, _, _| {
531531
match StackerDBConfig::from_smart_contract(chainstate, sortdb, &contract_id, 32, None) {
532532
Ok(config) => {
533533
let expected = result
534534
.clone()
535-
.expect(&format!("FATAL: parsed a bad contract\n{}", code));
535+
.unwrap_or_else(|| panic!("FATAL: parsed a bad contract\n{code}"));
536536
assert_eq!(config, expected);
537537
}
538538
Err(net_error::InvalidStackerDBContract(..)) => {
539539
assert!(
540540
result.is_none(),
541-
"FATAL: valid contract treated as invalid\n{}",
542-
code
541+
"FATAL: valid contract treated as invalid\n{code}"
543542
);
544543
}
545544
Err(e) => {
546-
panic!("Unexpected error: {:?}", &e);
545+
panic!("Unexpected error: {e:?}");
547546
}
548547
}
549548
Ok(())

0 commit comments

Comments
 (0)