use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("no logbook file at {path}. Run `logbook init` first (or set LOGBOOK_FILE to point elsewhere).")]
NotFound {
path: PathBuf,
},
#[error("--{flag} must be YYYY-MM-DD (got: \"{value}\")")]
BadDate {
flag: String,
value: String,
},
#[error("failed to {action} {path}: {source}")]
Io {
action: String,
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("git command failed: {0}")]
Git(String),
#[error("no editor configured — set $EDITOR or $VISUAL, or pass --why directly")]
NoEditor,
#[error("editor command failed: {0}")]
Editor(String),
#[error("aborting: empty entry (no why text was provided)")]
EmptyEntry,
#[error("no entry dated {0} to supersede — check `logbook list` for valid dates")]
SupersedeTargetMissing(String),
}
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub fn io(action: impl Into<String>, path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Error::Io {
action: action.into(),
path: path.into(),
source,
}
}
}