use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("{0}: not a directory")]
NotADirectory(PathBuf),
#[error(transparent)]
Query(#[from] QueryError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Format(#[from] crate::format::FormatError),
#[error("{path}: {reason}")]
Corrupt { path: PathBuf, reason: String },
#[error("{path}: format version {version} is newer than this build supports")]
Incompatible { path: PathBuf, version: u32 },
#[error("no index at {0} (run `ripindex index` first)")]
NoIndex(PathBuf),
#[error("{0}: another writer holds the index lock")]
Locked(PathBuf),
#[error("{0}: not found (possibly retired by a concurrent commit)")]
Vanished(PathBuf),
}
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum QueryError {
#[error("empty query")]
Empty,
#[error("unexpected {found:?} at byte {at}")]
Unexpected { found: String, at: usize },
#[error("unterminated phrase starting at byte {at}")]
UnterminatedPhrase { at: usize },
#[error("unbalanced parenthesis at byte {at}")]
UnbalancedParen { at: usize },
#[error("negation needs a positive term to subtract from (e.g. `foo -bar`)")]
OnlyNegation,
}
pub type Result<T> = std::result::Result<T, Error>;