Skip to content

Commit 9d7a2d0

Browse files
PatStilesuri-99
andauthored
fix(code quality): Remove panics from functions that return result (#1013)
Co-authored-by: Urix <[email protected]>
1 parent d70ac35 commit 9d7a2d0

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

batcher/aligned-batcher/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ impl Batcher {
327327

328328
pub async fn listen_connections(self: Arc<Self>, address: &str) -> Result<(), BatcherError> {
329329
// Create the event loop and TCP listener we'll accept connections on.
330-
let listener = TcpListener::bind(address).await.expect("Failed to build");
330+
let listener = TcpListener::bind(address)
331+
.await
332+
.map_err(|e| BatcherError::TcpListenerError(e.to_string()))?;
331333
info!("Listening on: {}", address);
332334

333335
// Let's spawn the handling of each connection in a separate task.

batcher/aligned-batcher/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ async fn main() -> Result<(), BatcherError> {
4646
// spawn task to listening for incoming blocks
4747
tokio::spawn({
4848
let app = batcher.clone();
49-
async move { app.listen_new_blocks().await.unwrap() }
49+
async move {
50+
app.listen_new_blocks()
51+
.await
52+
.expect("Error listening for new blocks exiting")
53+
}
5054
});
5155

5256
batcher.listen_connections(&addr).await?;

batcher/aligned-batcher/src/types/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ethers::types::SignatureError;
44
use tokio_tungstenite::tungstenite;
55

66
pub enum BatcherError {
7+
TcpListenerError(String),
78
ConnectionError(tungstenite::Error),
89
BatchVerifiedEventStreamError(String),
910
EthereumSubscriptionError(String),
@@ -33,6 +34,9 @@ impl From<SignatureError> for BatcherError {
3334
impl fmt::Debug for BatcherError {
3435
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3536
match self {
37+
BatcherError::TcpListenerError(e) => {
38+
write!(f, "TCP Listener error: {}", e)
39+
}
3640
BatcherError::ConnectionError(e) => {
3741
write!(f, "Web Socket Connection error: {}", e)
3842
}

batcher/aligned/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,16 @@ async fn main() -> Result<(), AlignedError> {
307307
.map_err(|e| SubmitError::GenericError(e.to_string()))?
308308
} else {
309309
warn!("Missing keystore used for payment. This proof will not be included if sent to Eth Mainnet");
310-
LocalWallet::from_str(ANVIL_PRIVATE_KEY).expect("Failed to create wallet")
310+
match LocalWallet::from_str(ANVIL_PRIVATE_KEY) {
311+
Ok(wallet) => wallet,
312+
Err(e) => {
313+
warn!(
314+
"Failed to create wallet from anvil private key: {}",
315+
e.to_string()
316+
);
317+
return Ok(());
318+
}
319+
}
311320
};
312321

313322
let eth_rpc_url = submit_args.eth_rpc_url.clone();

0 commit comments

Comments
 (0)