use std::io;
use std::path::PathBuf;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid path {path:?}: {reason}")]
InvalidPath { path: PathBuf, reason: &'static str },
#[error("not found: {0:?}")]
NotFound(PathBuf),
#[error("already exists: {0:?}")]
AlreadyExists(PathBuf),
#[error("not a directory: {0:?}")]
NotADirectory(PathBuf),
#[error("is a directory: {0:?}")]
IsADirectory(PathBuf),
#[error("directory not empty: {0:?}")]
DirectoryNotEmpty(PathBuf),
#[error("unsupported file type at {0:?} (symlinks and special files are out of scope)")]
UnsupportedFileType(PathBuf),
#[error("cannot move {from:?} into its own subtree {to:?}")]
InvalidMove { from: PathBuf, to: PathBuf },
#[error("{path:?} collides with existing entry {existing:?} on a case-insensitive filesystem")]
CaseCollision { path: PathBuf, existing: PathBuf },
#[error("{0:?} was changed outside the transaction")]
Conflict(PathBuf),
#[error("unsupported filesystem: missing {missing:?}")]
UnsupportedFilesystem { missing: Vec<&'static str> },
#[error("fstx v0.1 only has a Linux backend")]
UnsupportedPlatform,
#[error("recovery required for {tx}: {reason}")]
RecoveryRequired { tx: String, reason: String },
#[error("commit outcome unknown for {tx}; run fstx::recover")]
CommitOutcomeUnknown {
tx: String,
#[source]
source: io::Error,
},
#[error("commit failed ({cause}) and rollback failed ({rollback}); run fstx::recover")]
RollbackFailed {
cause: Box<Error>,
rollback: Box<Error>,
},
#[error(transparent)]
Io(#[from] io::Error),
}