diff --git a/kondo-lib/src/lib.rs b/kondo-lib/src/lib.rs index 3ec49d6..9752f73 100644 --- a/kondo-lib/src/lib.rs +++ b/kondo-lib/src/lib.rs @@ -1,4 +1,7 @@ -use std::{error, fs, path}; +use std::{ + error::{self, Error}, + fs, path, +}; const SYMLINK_FOLLOW: bool = true; @@ -329,13 +332,13 @@ pub fn clean(project_path: &str) -> Result<(), Box> { Ok(()) } - -pub fn path_canonicalise(base: &path::Path, tail: path::PathBuf) -> path::PathBuf { +pub fn path_canonicalise( + base: &path::Path, + tail: path::PathBuf, +) -> Result> { if tail.is_absolute() { - tail + Ok(tail) } else { - base.join(tail) - .canonicalize() - .expect("Unable to canonicalize!") + Ok(base.join(tail).canonicalize()?) } } diff --git a/kondo/src/main.rs b/kondo/src/main.rs index ceb2594..8ee372b 100644 --- a/kondo/src/main.rs +++ b/kondo/src/main.rs @@ -19,13 +19,13 @@ struct Opt { fn prepare_directories(dirs: Vec) -> Result, Box> { let cd = current_dir()?; - Ok(if dirs.is_empty() { - vec![cd] - } else { - dirs.into_iter() - .map(|d| path_canonicalise(&cd, d)) - .collect() - }) + if dirs.is_empty() { + return Ok(vec![cd]); + } + + dirs.into_iter() + .map(|d| path_canonicalise(&cd, d)) + .collect() } fn main() -> Result<(), Box> {