Skip to main content

opencode_provider_manager/omo_config/
error.rs

1//! Error types for agent-config.
2
3use std::path::PathBuf;
4
5/// Result type alias for agent-config operations.
6pub type Result<T> = std::result::Result<T, AgentConfigError>;
7
8/// Errors that can occur when working with agent configurations.
9#[derive(Debug, thiserror::Error)]
10pub enum AgentConfigError {
11    /// Failed to read a config file.
12    #[error("Failed to read config file at {path}: {source}")]
13    ReadError {
14        path: PathBuf,
15        #[source]
16        source: std::io::Error,
17    },
18
19    /// Failed to write a config file.
20    #[error("Failed to write config file at {path}: {source}")]
21    WriteError {
22        path: PathBuf,
23        #[source]
24        source: std::io::Error,
25    },
26
27    /// Failed to parse JSON.
28    #[error("JSON parse error in {path}: {source}")]
29    JsonParseError {
30        path: PathBuf,
31        #[source]
32        source: serde_json::Error,
33    },
34
35    /// Failed to parse TOML.
36    #[error("TOML parse error in {path}: {source}")]
37    TomlParseError {
38        path: PathBuf,
39        #[source]
40        source: Box<toml::de::Error>,
41    },
42
43    /// Failed to parse YAML.
44    #[error("YAML parse error in {path}: {source}")]
45    YamlParseError {
46        path: PathBuf,
47        #[source]
48        source: Box<serde_yaml::Error>,
49    },
50
51    /// Failed to serialize config.
52    #[error("Serialization error: {0}")]
53    SerializeError(#[from] serde_json::Error),
54
55    /// Validation error — config does not conform to the schema.
56    #[error("Validation error: {0}")]
57    ValidationError(String),
58
59    /// Config file not found.
60    #[error("Config file not found: {0}")]
61    NotFound(PathBuf),
62
63    /// Unsupported file format.
64    #[error("Unsupported config format '{format}' for file {path}")]
65    UnsupportedFormat { format: String, path: PathBuf },
66
67    /// Layer is invalid or unsupported.
68    #[error("Invalid config layer: {0}")]
69    InvalidLayer(String),
70
71    /// Generic I/O error.
72    #[error("I/O error: {0}")]
73    Io(#[from] std::io::Error),
74
75    /// Other errors.
76    #[error("{0}")]
77    Other(String),
78}