use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("repository path must be absolute: {0}")]
RepoPathNotAbsolute(PathBuf),
#[error("repo not found: {0}")]
RepoNotFound(PathBuf),
#[error("not a directory: {0}")]
NotADirectory(PathBuf),
#[error("file or directory does not exist: {0}")]
PathNotExist(PathBuf),
#[error("expected repo-relative path, got absolute: {0}")]
PathNotRelative(PathBuf),
#[error("key must not be empty")]
EmptyKey,
#[error("password must not be empty")]
EmptyPassword,
#[error("no file to {0}")]
NoFile(&'static str),
#[error("invalid magic bytes")]
InvalidMagic,
#[error("unsupported version: {0}")]
UnsupportedVersion(u8),
#[error("unsupported encryption algorithm: {0}")]
UnsupportedAlgo(u8),
#[error("corrupt header in {0}")]
CorruptHeader(PathBuf),
#[error("encryption failed: {0}")]
EncryptFailed(String),
#[error("decryption failed (wrong password, corrupt, or tampered data): {0}")]
DecryptFailed(String),
#[error("Argon2 key derivation failed: {0}")]
Argon2(String),
#[error("truncated chunk: nonce present but no ciphertext follows")]
TruncatedChunk,
#[error("file truncation detected! the ciphertext is incomplete")]
FileTruncated,
#[error("failed to persist atomic write to {0}: {1}")]
AtomicPersist(PathBuf, String),
#[error("git command failed: {0}")]
Git(String),
#[error("a pre-commit hook already exists at {0}; remove it manually before installing")]
HookExists(PathBuf),
#[error("{0} out of {1} files are not encrypted")]
FilesNotEncrypted(usize, usize),
#[error("config error: {0}")]
Config(String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("salt cache serialization error: {0}")]
SaltCache(String),
#[error("{0}")]
Other(String),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;