From 8ea23078152ac5ffe747b0ac6518119ba7315715 Mon Sep 17 00:00:00 2001 From: Arash Outadi Date: Sat, 4 Jul 2020 18:03:12 -0700 Subject: [PATCH] More informative error messages when "rm" fails (#2109) * add a nicer error message * small fix to message and remove log --- crates/nu-cli/src/shell/filesystem_shell.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/nu-cli/src/shell/filesystem_shell.rs b/crates/nu-cli/src/shell/filesystem_shell.rs index 874cb41e7..91c1a1fa6 100644 --- a/crates/nu-cli/src/shell/filesystem_shell.rs +++ b/crates/nu-cli/src/shell/filesystem_shell.rs @@ -15,6 +15,7 @@ use crate::utils::FileStructure; use rustyline::completion::FilenameCompleter; use rustyline::hint::{Hinter, HistoryHinter}; use std::collections::HashMap; +use std::io::{Error, ErrorKind}; use std::path::{Path, PathBuf}; #[cfg(unix)] @@ -587,25 +588,27 @@ impl Shell for FilesystemShell { .map(|val| val.is_true()) .unwrap_or(false); result = if _trash.item || (rm_always_trash && !_permanent.item) { - trash::remove(&f).map_err(|_| f.to_string_lossy()) + trash::remove(&f).map_err(|e: trash::Error| { + Error::new(ErrorKind::Other, format!("{:?}", e)) + }) } else if metadata.is_file() { - std::fs::remove_file(&f).map_err(|_| f.to_string_lossy()) + std::fs::remove_file(&f) } else { - std::fs::remove_dir_all(&f).map_err(|_| f.to_string_lossy()) + std::fs::remove_dir_all(&f) }; } #[cfg(not(feature = "trash-support"))] { result = if metadata.is_file() { - std::fs::remove_file(&f).map_err(|_| f.to_string_lossy()) + std::fs::remove_file(&f) } else { - std::fs::remove_dir_all(&f).map_err(|_| f.to_string_lossy()) + std::fs::remove_dir_all(&f) }; } if let Err(e) = result { - let msg = format!("Could not delete {:}", e); - Err(ShellError::labeled_error(msg, e, tag)) + let msg = format!("Could not delete because: {:}", e); + Err(ShellError::labeled_error(msg, e.to_string(), tag)) } else { let val = format!("deleted {:}", f.to_string_lossy()).into(); Ok(ReturnSuccess::Value(val))