Skip to content

Commit 3ad2ded

Browse files
committed
better error handling
1 parent 15a2105 commit 3ad2ded

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/health/safe_block.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,21 @@ pub async fn subscribe_to_new_heads(
225225
}
226226
Ok(None) => {
227227
// Handle the case where the channel is closed
228+
log_err!("newHeads channel closed.");
228229
panic!("FATAL: Channel closed in newHeads subscription.");
229230
}
230231
Err(_) => {
231232
// Handle the timeout case
232233
{
233234
let mut nn_rwlock = cache_args.named_numbers.write().unwrap();
234235
nn_rwlock.latest = 0;
235-
incoming_tx.send(WsconnMessage::Reconnect()).unwrap();
236+
match incoming_tx.send(WsconnMessage::Reconnect()) {
237+
Ok(_) => {},
238+
Err(_) => {
239+
log_err!("WS incoming channel closed.");
240+
panic!("FATAL: WS module failed trying to reinitialize! Please restart Blutgang!");
241+
},
242+
}
236243
}
237244
log_wrn!("Timeout in newHeads subscription, possible connection failiure or missed block.");
238245
let node_id = match sub_data.get_node_from_id(&subscription_id) {

src/rpc/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Rpc {
160160
});
161161

162162
let number: Value =
163-
unsafe { simd_json::serde::from_str(&mut self.send_request(request).await?).unwrap() };
163+
unsafe { simd_json::serde::from_str(&mut self.send_request(request).await?)? };
164164
let number = &number["result"]["number"];
165165

166166
let number = match number.as_str() {

src/websocket/client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ pub async fn ws_conn(
197197
let rax = match unsafe { from_str(&mut ws_message) } {
198198
Ok(rax) => rax,
199199
Err(_e) => {
200-
#[cfg(feature = "debug-verbose")]
201-
log_wrn!("Couldn't deserialize ws_conn response: {}", _e);
200+
#[cfg(feature = "debug-verbose")] {
201+
use crate::log_wrn;
202+
log_wrn!("Couldn't deserialize ws_conn response: {}", _e);
203+
}
202204

203205
continue;
204206
}

0 commit comments

Comments
 (0)