From 5e05bfa2ef5dbefe1c55d26eda31f1e84e206ef9 Mon Sep 17 00:00:00 2001 From: Lux Aliaga Date: Mon, 17 Oct 2022 19:56:23 -0300 Subject: [PATCH] src: Removed unnecessary contexts This commit should remove some contexts that actually made some errors more difficult to read. They will now display the idiomatic errors generated by anyhow. --- src/inv.rs | 10 +++------- src/item.rs | 15 +++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/inv.rs b/src/inv.rs index 8ab9e87..701d82d 100644 --- a/src/inv.rs +++ b/src/inv.rs @@ -34,9 +34,7 @@ pub fn init() -> Result<()> { let mut answer = String::new(); print!("⚠️ {} Vento has already been initialized. Reinitializing will delete all files on the directory for Vento. Do you wish to proceed? (y/N) ", "WARNING:".bold().red()); let _ = io::stdout().flush(); - io::stdin() - .read_line(&mut answer) - .context("Failed to read input")?; + io::stdin().read_line(&mut answer)?; match answer.as_str().trim() { "y" | "Y" => fs::remove_dir_all(&ventodir)?, _ => process::exit(0), @@ -190,10 +188,8 @@ fn create_slots() -> Result<()> { let active = &common::env_config()?.active_dir; let inactive = &common::env_config()?.inactive_dir; - let initialize_error = "Vento was unable to initalize. Do you have the correct permissions?"; - - fs::create_dir_all(active).context(initialize_error)?; - fs::create_dir_all(inactive).context(initialize_error)?; + fs::create_dir_all(active)?; + fs::create_dir_all(inactive)?; println!("🎉 {}", "Vento has been succesfully initialized!".green()); Ok(()) diff --git a/src/item.rs b/src/item.rs index 7cbfa06..f2f38a2 100644 --- a/src/item.rs +++ b/src/item.rs @@ -18,7 +18,7 @@ */ use super::common; -use anyhow::{bail, Context, Result}; +use anyhow::{bail, Result}; use colored::Colorize; use fs_extra::dir::{move_dir, CopyOptions}; use std::fs; @@ -80,11 +80,11 @@ pub fn take(file: &String, slot: &str) -> Result<()> { if sourcepath.is_file() | sourcepath.is_symlink() { // Checks the path's file type - fs::copy(&file, &destpath).context("Vento was unable to copy the file.")?; - fs::remove_file(&file).context("Vento was unable to remove the file.")?; + fs::copy(&file, &destpath)?; + fs::remove_file(&file)?; } else if sourcepath.is_dir() { let options = CopyOptions::new(); - move_dir(&file, &slotdir, &options).context("Vento was unable to move the directory.")?; + move_dir(&file, &slotdir, &options)?; } else { bail!("{}", "No such file or directory.".red()); } @@ -138,13 +138,12 @@ pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> { if sourcepath.is_file() | sourcepath.is_symlink() { // Checks the path's file type - fs::copy(&sourcepath, &destpath).context("Vento was unable to copy the file.")?; - fs::remove_file(&sourcepath).context("Vento was unable to remove the file.")?; + fs::copy(&sourcepath, &destpath)?; + fs::remove_file(&sourcepath)?; } else if sourcepath.is_dir() { let destpath: PathBuf = Path::new(&dest).to_path_buf(); let options = CopyOptions::new(); - move_dir(&sourcepath, &destpath, &options) - .context("Vento was unable to move the directory.")?; + move_dir(&sourcepath, &destpath, &options)?; } else { bail!("{}", "No such file or directory.".red()); }