use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum DagError {
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("budget exceeded: {label} (limit {limit})")]
BudgetExceeded {
label: String,
limit: u64,
},
#[error("invalid result: {0}")]
InvalidResult(String),
#[error("overflow: {0}")]
Overflow(String),
#[error("io error on {}: {source}", path.display())]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("dgc format error: {0}")]
DgcFormat(String),
#[error("obj parse error at line {line}: {reason}")]
ObjParse {
line: usize,
reason: String,
},
}
impl DagError {
pub(crate) fn invalid_input(message: impl Into<String>) -> Self {
Self::InvalidInput(message.into())
}
pub(crate) fn budget_exceeded(label: impl Into<String>, limit: u64) -> Self {
Self::BudgetExceeded { label: label.into(), limit }
}
pub(crate) fn overflow(message: impl Into<String>) -> Self {
Self::Overflow(message.into())
}
pub(crate) fn dgc_format(message: impl Into<String>) -> Self {
Self::DgcFormat(message.into())
}
}
pub type DagResult<T> = Result<T, DagError>;