From 50f53dc480fda8b3daab7a34454c2dd9f3f5f991 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Sat, 9 Mar 2024 15:34:57 +0100 Subject: Improve the error handling --- src/command/publish.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/command/publish.rs') diff --git a/src/command/publish.rs b/src/command/publish.rs index 207b45d..34ca0d2 100644 --- a/src/command/publish.rs +++ b/src/command/publish.rs @@ -1,4 +1,4 @@ -use std::io::Result; +use std::io::{Error, ErrorKind::Other, Result}; use crate::configuration::Configuration; use std::process::{Command, Stdio}; @@ -19,14 +19,15 @@ impl super::Command for Publish { fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> { - let input = input.expect("You must provide a location to publish the blog"); + let input = input + .ok_or_else(|| Error::new(Other, "You must provide a location to publish the blog"))?; Command::new(COMMAND) .arg("--version") .stdout(Stdio::null()) .stderr(Stdio::null()) .status() - .expect("Publishing requires rsync"); + .map_err(|_| Error::new(Other, "Publishing requires rsync"))?; Command::new(COMMAND) @@ -36,7 +37,7 @@ impl super::Command for Publish { .stdout(Stdio::null()) .stderr(Stdio::null()) .status() - .expect("Publishing requires rsync"); + .map_err(|_| Error::new(Other, "Rsync failed to publish."))?; return Ok(()) } -- cgit