Эх сурвалжийг харах

Improve some error handling

PR (#45)
Dastan-glitch 4 жил өмнө
parent
commit
86ec332b71

+ 1 - 1
README.md

@@ -70,7 +70,7 @@ N.B. On OSX this is `/Users/x/Library/Application Support/darkfi`.
 ## Bash Completion
 This will add the options auto completion of `drk` and `darkfid`.
 ```shell
-% echo source ./auto-complete >> ~/.bashrc
+% echo source $(pwd)/contrib/auto-complete >> ~/.bashrc
 ```
 
 ## Usage

+ 2 - 2
src/rpc/rpcserver.rs

@@ -65,7 +65,7 @@ async fn serve(
             };
 
             let reply = rh.handle_request(r, executor.clone()).await;
-            let j = serde_json::to_string(&reply).unwrap();
+            let j = serde_json::to_string(&reply)?;
             debug!(target: "RPC", "<-- {}", j);
 
             if let Err(e) = stream.write_all(j.as_bytes()).await {
@@ -99,7 +99,7 @@ async fn serve(
                 };
 
                 let reply = rh.handle_request(r, executor.clone()).await;
-                let j = serde_json::to_string(&reply).unwrap();
+                let j = serde_json::to_string(&reply)?;
                 debug!(target: "RPC", "<-- {}", j);
 
                 if let Err(e) = stream.write_all(j.as_bytes()).await {

+ 15 - 2
src/service/gateway.rs

@@ -180,7 +180,12 @@ pub struct GatewayClient {
 impl GatewayClient {
     pub fn new(addr: Url, sub_addr: Url, rocks: RocksColumn<columns::Slabs>) -> Result<Self> {
         // TODO: We'll want differentiation between TCP and TLS here.
-        let addr_sock = (addr.host().unwrap().to_string(), addr.port().unwrap())
+        let addr_sock = (
+            addr.host()
+                .ok_or_else(|| Error::UrlParseError(format!("Missing host in {}", addr)))?
+                .to_string(),
+            addr.port().ok_or_else(|| Error::UrlParseError(format!("Missing port in {}", addr)))?,
+        )
             .to_socket_addrs()?
             .next()
             .ok_or(Error::NoUrlFound)?;
@@ -190,7 +195,15 @@ impl GatewayClient {
 
         let (gateway_slabs_sub_s, gateway_slabs_sub_rv) = async_channel::unbounded::<Slab>();
 
-        let sub_addr_sock = (sub_addr.host().unwrap().to_string(), sub_addr.port().unwrap())
+        let sub_addr_sock = (
+            sub_addr
+                .host()
+                .ok_or_else(|| Error::UrlParseError(format!("Missing host in {}", sub_addr)))?
+                .to_string(),
+            sub_addr
+                .port()
+                .ok_or_else(|| Error::UrlParseError(format!("Missing port in {}", sub_addr)))?,
+        )
             .to_socket_addrs()?
             .next()
             .ok_or(Error::NoUrlFound)?;

+ 1 - 2
src/service/sol.rs

@@ -164,8 +164,7 @@ impl SolClient {
             let message = read
                 .next()
                 .await
-                .ok_or_else(|| Error::TungsteniteError("No more messages".to_string()))?;
-            let message = message?;
+                .ok_or_else(|| Error::TungsteniteError("No more messages".to_string()))??;
 
             if let Message::Pong(_) = message.clone() {
                 if sub_iter > 60 * 10 {