Skip to content

Commit af66417

Browse files
committed
Fix clippy expect_fun_call warnings
1 parent 4eb891c commit af66417

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct Config {
4949
fn str_to_socketaddr(address: &str, what: &str) -> SocketAddr {
5050
address
5151
.to_socket_addrs()
52-
.expect(&format!("unable to resolve {} address", what))
52+
.unwrap_or_else(|_| panic!("unable to resolve {} address", what))
5353
.collect::<Vec<_>>()
5454
.pop()
5555
.unwrap()

src/electrum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ impl RPC {
576576
let chan = Channel::unbounded();
577577
let acceptor = chan.sender();
578578
spawn_thread("acceptor", move || {
579-
let listener = TcpListener::bind(addr).expect(&format!("bind({}) failed", addr));
579+
let listener =
580+
TcpListener::bind(addr).unwrap_or_else(|_| panic!("bind({}) failed", addr));
580581
info!("Electrum RPC server running on {}", addr);
581582
loop {
582583
let (stream, addr) = listener.accept().expect("accept failed");

src/metrics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ impl Metrics {
6767
}
6868

6969
pub fn start(&self) {
70-
let server = tiny_http::Server::http(self.addr).expect(&format!(
71-
"failed to start monitoring HTTP server at {}",
72-
self.addr
73-
));
70+
let server = tiny_http::Server::http(self.addr)
71+
.unwrap_or_else(|_| panic!("failed to start monitoring HTTP server at {}", self.addr));
7472
start_process_exporter(&self);
7573
let reg = self.reg.clone();
7674
spawn_thread("metrics", move || loop {

src/new_index/fetch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ fn blkfiles_reader(blk_files: Vec<PathBuf>) -> Fetcher<Vec<u8>> {
158158
spawn_thread("blkfiles_reader", move || {
159159
for path in blk_files {
160160
trace!("reading {:?}", path);
161-
let blob = fs::read(&path).expect(&format!("failed to read {:?}", path));
161+
let blob = fs::read(&path).unwrap_or_else(|_| panic!("failed to read {:?}", path));
162162
sender
163163
.send(blob)
164-
.expect(&format!("failed to send {:?} contents", path));
164+
.unwrap_or_else(|_| panic!("failed to send {:?} contents", path));
165165
}
166166
}),
167167
)

src/new_index/mempool.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ impl Mempool {
323323
.map(|(index, txi)| {
324324
(
325325
index as u32,
326-
txos.get(&txi.previous_output)
327-
.expect(&format!("missing outpoint {:?}", txi.previous_output)),
326+
txos.get(&txi.previous_output).unwrap_or_else(|| {
327+
panic!("missing outpoint {:?}", txi.previous_output)
328+
}),
328329
)
329330
})
330331
.collect();
@@ -445,7 +446,7 @@ impl Mempool {
445446
for txid in &to_remove {
446447
self.txstore
447448
.remove(*txid)
448-
.expect(&format!("missing mempool tx {}", txid));
449+
.unwrap_or_else(|| panic!("missing mempool tx {}", txid));
449450

450451
self.feeinfo.remove(*txid).or_else(|| {
451452
warn!("missing mempool tx feeinfo {}", txid);

src/new_index/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ fn index_transaction(
10561056
}
10571057
let prev_txo = previous_txos_map
10581058
.get(&txi.previous_output)
1059-
.expect(&format!("missing previous txo {}", txi.previous_output));
1059+
.unwrap_or_else(|| panic!("missing previous txo {}", txi.previous_output));
10601060

10611061
let history = TxHistoryRow::new(
10621062
&prev_txo.script_pubkey,

src/util/block.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ impl HeaderList {
9292
let null_hash = BlockHash::default();
9393

9494
while blockhash != null_hash {
95-
let header = headers_map.remove(&blockhash).expect(&format!(
96-
"missing expected blockhash in headers map: {:?}",
97-
blockhash
98-
));
95+
let header = headers_map.remove(&blockhash).unwrap_or_else(|| {
96+
panic!("missing expected blockhash in headers map: {:?}", blockhash)
97+
});
9998
blockhash = header.prev_blockhash;
10099
headers_chain.push(header);
101100
}
@@ -138,7 +137,7 @@ impl HeaderList {
138137
0
139138
} else {
140139
self.header_by_blockhash(&prev_blockhash)
141-
.expect(&format!("{} is not part of the blockchain", prev_blockhash))
140+
.unwrap_or_else(|| panic!("{} is not part of the blockchain", prev_blockhash))
142141
.height()
143142
+ 1
144143
};

0 commit comments

Comments
 (0)