From fe69bf144a95e2f46339495f1c8ba1e45cc9806a Mon Sep 17 00:00:00 2001 From: lunar-mining Date: Thu, 19 May 2022 11:27:06 +0200 Subject: [PATCH] dnetview: explicit error handling when opening an RPC channel --- bin/dnetview/src/main.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/dnetview/src/main.rs b/bin/dnetview/src/main.rs index dd9bc4218..d6848f125 100644 --- a/bin/dnetview/src/main.rs +++ b/bin/dnetview/src/main.rs @@ -43,8 +43,10 @@ struct DnetView { impl DnetView { async fn new(url: Url, name: String) -> Result { - let rpc_client = RpcClient::new(url).await?; - Ok(Self { name, rpc_client }) + match RpcClient::new(url).await { + Ok(rpc_client) => return Ok(Self { name, rpc_client }), + Err(e) => return Err(Error::OperationFailed), + } } // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 42} @@ -123,8 +125,11 @@ async fn poll_and_update_model( model: Arc, ) -> DnetViewResult<()> { for node in &config.nodes { - let client = DnetView::new(Url::parse(&node.rpc_url)?, node.name.clone()).await?; - ex.spawn(poll(client, model.clone())).detach(); + info!("Attempting to poll {}, RPC URL: {}", node.name, node.rpc_url); + match DnetView::new(Url::parse(&node.rpc_url)?, node.name.clone()).await { + Ok(client) => return Ok(ex.spawn(poll(client, model.clone())).detach()), + Err(e) => return Err(DnetViewError::Darkfi(e)), + } } Ok(()) } @@ -140,8 +145,8 @@ async fn poll(client: DnetView, model: Arc) -> DnetViewResult<()> { } } Err(e) => { - parse_offline(&client, model.clone()).await?; error!("{:?}", e); + parse_offline(&client, model.clone()).await?; } } async_util::sleep(2).await;