]> git.r.bdr.sh - rbdr/blog/blobdiff - src/remote/git.rs
Improve the error handling
[rbdr/blog] / src / remote / git.rs
index a4c1c28d13a1faab79178af9144b0f9e73672814..66c5a89b115756bb06438a3f381c40080217e56e 100644 (file)
@@ -1,6 +1,6 @@
-use std::io::Result;
+use std::io::{Error, ErrorKind::Other, Result};
 use std::path::PathBuf;
-use std::process::Command;
+use std::process::{Command, Stdio};
 use std::time::{SystemTime, UNIX_EPOCH};
 
 pub struct Git;
@@ -19,7 +19,7 @@ impl super::Remote for Git {
 
     fn sync_up(&self, remote: &str, directory: &PathBuf) -> Result<()> {
         let timestamp = SystemTime::now().duration_since(UNIX_EPOCH)
-            .expect("Invalid time")
+            .map_err(|_| Error::new(Other, "Invalid time"))?
             .as_millis();
 
         let commands = vec![
@@ -33,8 +33,10 @@ impl super::Remote for Git {
             Command::new("sh")
                 .arg("-c")
                 .arg(&command)
+                .stdout(Stdio::null())
+                .stderr(Stdio::null())
                 .status()
-                .expect("Failed while performing sync up with git");
+                .map_err(|_| Error::new(Other, "Failed while performing sync up with git"))?;
         }
 
         Ok(())
@@ -52,8 +54,10 @@ impl super::Remote for Git {
             Command::new("sh")
                 .arg("-c")
                 .arg(&command)
+                .stdout(Stdio::null())
+                .stderr(Stdio::null())
                 .status()
-                .expect("Failed while performing sync down with git");
+                .map_err(|_| Error::new(Other, "Failed while performing sync down with git"))?;
         }
         Ok(())
     }