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