1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

mv: move to thiserror

This commit is contained in:
Sylvestre Ledru 2025-01-19 23:35:54 +01:00
parent 9de6393e2c
commit 6866eedc83
3 changed files with 21 additions and 29 deletions

1
Cargo.lock generated
View file

@ -2940,6 +2940,7 @@ dependencies = [
"clap",
"fs_extra",
"indicatif",
"thiserror 2.0.11",
"uucore",
]

View file

@ -26,6 +26,7 @@ uucore = { workspace = true, features = [
"fsxattr",
"update-control",
] }
thiserror = { workspace = true }
[[bin]]
name = "mv"

View file

@ -2,47 +2,37 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use std::error::Error;
use std::fmt::{Display, Formatter, Result};
use thiserror::Error;
use uucore::error::UError;
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum MvError {
#[error("cannot stat {0}: No such file or directory")]
NoSuchFile(String),
#[error("cannot stat {0}: Not a directory")]
CannotStatNotADirectory(String),
#[error("{0} and {1} are the same file")]
SameFile(String, String),
#[error("cannot move {0} to a subdirectory of itself, {1}")]
SelfTargetSubdirectory(String, String),
#[error("cannot overwrite directory {0} with non-directory")]
DirectoryToNonDirectory(String),
#[error("cannot overwrite non-directory {1} with directory {0}")]
NonDirectoryToDirectory(String, String),
#[error("target {0}: Not a directory")]
NotADirectory(String),
#[error("target directory {0}: Not a directory")]
TargetNotADirectory(String),
#[error("failed to access {0}: Not a directory")]
FailedToAccessNotADirectory(String),
}
impl Error for MvError {}
impl UError for MvError {}
impl Display for MvError {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::NoSuchFile(s) => write!(f, "cannot stat {s}: No such file or directory"),
Self::CannotStatNotADirectory(s) => write!(f, "cannot stat {s}: Not a directory"),
Self::SameFile(s, t) => write!(f, "{s} and {t} are the same file"),
Self::SelfTargetSubdirectory(s, t) => {
write!(f, "cannot move {s} to a subdirectory of itself, {t}")
}
Self::DirectoryToNonDirectory(t) => {
write!(f, "cannot overwrite directory {t} with non-directory")
}
Self::NonDirectoryToDirectory(s, t) => {
write!(f, "cannot overwrite non-directory {t} with directory {s}")
}
Self::NotADirectory(t) => write!(f, "target {t}: Not a directory"),
Self::TargetNotADirectory(t) => write!(f, "target directory {t}: Not a directory"),
Self::FailedToAccessNotADirectory(t) => {
write!(f, "failed to access {t}: Not a directory")
}
}
}
}