1use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum TokenError {
9 #[error("Failed to read token file {path}: {source}")]
11 Io {
12 path: String,
13 source: std::io::Error,
14 },
15
16 #[error("Invalid token JSON in {path}: {source}")]
18 InvalidJson {
19 path: String,
20 source: serde_json::Error,
21 },
22
23 #[error("Invalid token file schema: {0}")]
25 Schema(String),
26
27 #[error(
29 "Token --{token} required by caller but not found in theme '{theme}'. Add --{token} to the theme or remove it from the required list."
30 )]
31 MissingToken {
32 theme: String,
34 token: String,
36 },
37}
38
39impl TokenError {
40 pub(crate) fn io(path: &std::path::Path, source: std::io::Error) -> Self {
42 Self::Io {
43 path: path.display().to_string(),
44 source,
45 }
46 }
47
48 pub(crate) fn json(path: &std::path::Path, source: serde_json::Error) -> Self {
50 Self::InvalidJson {
51 path: path.display().to_string(),
52 source,
53 }
54 }
55}
56
57pub type Result<T> = std::result::Result<T, TokenError>;