1use std::fmt;
2
3use crate::path::TagPathError;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum Error {
8 InvalidPath(TagPathError),
10 PathNotFound(String),
12 CannotMoveRoot,
14 CannotRemoveRoot,
16 CannotMoveIntoDescendant { from: String, to: String },
18}
19
20impl fmt::Display for Error {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::InvalidPath(error) => error.fmt(f),
24 Self::PathNotFound(path) => write!(f, "path not found: {path}"),
25 Self::CannotMoveRoot => write!(f, "cannot move the root path"),
26 Self::CannotRemoveRoot => write!(f, "cannot remove the root path"),
27 Self::CannotMoveIntoDescendant { from, to } => {
28 write!(f, "cannot move {from} into its descendant {to}")
29 }
30 }
31 }
32}
33
34impl std::error::Error for Error {}
35
36impl From<TagPathError> for Error {
37 fn from(error: TagPathError) -> Self {
38 Self::InvalidPath(error)
39 }
40}
41
42pub type Result<T> = std::result::Result<T, Error>;