opys_engine/error.rs
1use std::path::PathBuf;
2
3/// Errors raised by library operations.
4///
5/// Content problems found by `verify` are *not* errors — they are collected
6/// into a list and reported with a dedicated exit code. These variants cover
7/// usage mistakes and runtime/IO failures.
8#[derive(Debug, thiserror::Error)]
9pub enum OpysError {
10 #[error("{0} not found — run 'opys init' first")]
11 ConfigNotFound(PathBuf),
12
13 #[error("{id} not found")]
14 NotFound { id: String },
15
16 /// A usage mistake (bad flags, failed guard, etc.). Mirrors the Python
17 /// tool's `sys.exit("error: …")` cases.
18 #[error("{0}")]
19 Usage(String),
20
21 /// A failure inside the in-memory SQL store (a malformed internal
22 /// statement, an impossible decode). Always a bug, never user error —
23 /// the message is prefixed so tests can never accidentally match it.
24 #[error("internal store error: {0}")]
25 Store(String),
26
27 #[error("{path}: {source}")]
28 Toml {
29 path: PathBuf,
30 #[source]
31 source: toml::de::Error,
32 },
33
34 #[error(transparent)]
35 Io(#[from] std::io::Error),
36}
37
38/// Convenience for raising a usage error.
39pub fn usage(msg: impl Into<String>) -> OpysError {
40 OpysError::Usage(msg.into())
41}
42
43pub type Result<T> = std::result::Result<T, OpysError>;