1use std::path::PathBuf;
7
8#[derive(Debug, thiserror::Error)]
10pub enum DagError {
11 #[error("invalid input: {0}")]
13 InvalidInput(String),
14
15 #[error("budget exceeded: {label} (limit {limit})")]
17 BudgetExceeded {
18 label: String,
20 limit: u64,
22 },
23
24 #[error("invalid result: {0}")]
26 InvalidResult(String),
27
28 #[error("overflow: {0}")]
30 Overflow(String),
31
32 #[error("io error on {}: {source}", path.display())]
34 Io {
35 path: PathBuf,
37 #[source]
39 source: std::io::Error,
40 },
41
42 #[error("dgc format error: {0}")]
44 DgcFormat(String),
45
46 #[error("obj parse error at line {line}: {reason}")]
48 ObjParse {
49 line: usize,
51 reason: String,
53 },
54}
55
56impl DagError {
57 pub(crate) fn invalid_input(message: impl Into<String>) -> Self {
59 Self::InvalidInput(message.into())
60 }
61
62 pub(crate) fn budget_exceeded(label: impl Into<String>, limit: u64) -> Self {
64 Self::BudgetExceeded { label: label.into(), limit }
65 }
66
67 pub(crate) fn overflow(message: impl Into<String>) -> Self {
69 Self::Overflow(message.into())
70 }
71
72 pub(crate) fn dgc_format(message: impl Into<String>) -> Self {
74 Self::DgcFormat(message.into())
75 }
76}
77
78pub type DagResult<T> = Result<T, DagError>;