Преглед изворни кода

dnetview: propagate errors more descriptively

lunar-mining пре 4 година
родитељ
комит
4541e00eac
2 измењених фајлова са 7 додато и 7 уклоњено
  1. 4 6
      bin/dnetview/src/main.rs
  2. 3 1
      bin/dnetview/src/view.rs

+ 4 - 6
bin/dnetview/src/main.rs

@@ -43,10 +43,8 @@ struct DnetView {
 
 impl DnetView {
     async fn new(url: Url, name: String) -> Result<Self> {
-        match RpcClient::new(url).await {
-            Ok(rpc_client) => return Ok(Self { name, rpc_client }),
-            Err(e) => return Err(Error::OperationFailed),
-        }
+        let rpc_client = RpcClient::new(url).await?;
+        Ok(Self { name, rpc_client })
     }
 
     // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 42}
@@ -58,11 +56,11 @@ impl DnetView {
 
     //--> {"jsonrpc": "2.0", "method": "poll", "params": [], "id": 42}
     // <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
-    async fn get_info(&self) -> Result<Value> {
+    async fn get_info(&self) -> DnetViewResult<Value> {
         let req = jsonrpc::request(json!("get_info"), json!([]));
         match self.rpc_client.request(req).await {
             Ok(req) => return Ok(req),
-            Err(_e) => return Err(Error::OperationFailed),
+            Err(e) => return Err(DnetViewError::Darkfi(e)),
         }
     }
 }

+ 3 - 1
bin/dnetview/src/view.rs

@@ -17,7 +17,7 @@ use crate::{
     error::{DnetViewError, DnetViewResult},
     model::{NodeInfo, SelectableObject},
 };
-//use log::debug;
+use log::debug;
 
 #[derive(Debug)]
 pub struct View {
@@ -99,6 +99,8 @@ impl View {
         // remove any duplicates
         id_list.dedup();
 
+        //debug!("ID LIST {:?}", id_list);
+        //debug!("ACTIVE ID LIST {:?}", self.active_ids.ids);
         if id_list.is_empty() {
             // we have not received any data
             Ok(())