Skip to content

Commit

Permalink
Optimize error handling
Browse files Browse the repository at this point in the history
Error Handling Improvement: In the `enable_listener` method, use if let Err(e) for error handling instead of directly using expect. This can prevent the program from crashing when an error occurs. The expect method will cause the program to crash and print the specified error message when an error is encountered. This is useful during development and debugging because it helps quickly locate the problem. However, in a production environment, directly crashing may not be the best choice as it can lead to service interruptions.
  • Loading branch information
ylmin authored Jul 13, 2024
1 parent cc78dae commit 7c81d96
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion node/router/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ pub trait Routing<N: Network>:

// Start listening for inbound connections.
async fn enable_listener(&self) {
self.tcp().enable_listener().await.expect("Failed to enable the TCP listener");
if let Err(e) = self.tcp().enable_listener().await {
eprintln!("Failed to enable the TCP listener: {:?}", e);
}
}

/// Initialize a new instance of the heartbeat.
Expand Down

0 comments on commit 7c81d96

Please sign in to comment.