Skip to main content

modular_agent_core/
error.rs

1use thiserror::Error;
2
3/// Errors that occur during agent operations.
4///
5/// Errors are categorized into:
6///
7/// - **Configuration errors**: `InvalidConfig`, `UnknownConfig`, `NoConfig`
8/// - **Value errors**: `InvalidValue`, `InvalidArrayValue`
9/// - **Agent management errors**: `AgentNotFound`, `AgentAlreadyExists`
10/// - **Connection errors**: `ConnectionNotFound`, `ConnectionAlreadyExists`
11/// - **I/O errors**: `IoError`, `SerializationError`, `JsonParseError`
12///
13/// - **設定エラー**: `InvalidConfig`, `UnknownConfig`, `NoConfig`
14/// - **値エラー**: `InvalidValue`, `InvalidArrayValue`
15/// - **エージェント管理エラー**: `AgentNotFound`, `AgentAlreadyExists`
16/// - **接続エラー**: `ConnectionNotFound`, `ConnectionAlreadyExists`
17/// - **I/Oエラー**: `IoError`, `SerializationError`, `JsonParseError`
18#[derive(Clone, Debug, Error)]
19pub enum AgentError {
20    /// Invalid value in an array element.
21    #[error("Invalid {0} value in array")]
22    InvalidArrayValue(String),
23
24    /// Agent definition is invalid.
25    #[error("{0}: Agent definition \"{1}\" is invalid")]
26    InvalidDefinition(String, String),
27
28    /// Invalid port name.
29    #[error("Invalid port: {0}")]
30    InvalidPin(String),
31
32    /// Invalid preset name.
33    #[error("Invalid preset name: {0}")]
34    InvalidPresetName(String),
35
36    /// Invalid value for the expected type.
37    #[error("Invalid {0} value")]
38    InvalidValue(String),
39
40    /// Agent definition is missing a required field.
41    #[error("{0}: Agent definition \"{1}\" is missing")]
42    MissingDefinition(String, String),
43
44    /// Failed to rename a preset.
45    #[error("Failed to rename preset: {0}")]
46    RenamePresetFailed(String),
47
48    /// Unknown agent definition kind.
49    #[error("Unknown agent def kind: {0}")]
50    UnknownDefKind(String),
51
52    /// Unknown agent definition name.
53    #[error("Unknown agent def name: {0}")]
54    UnknownDefName(String),
55
56    /// Agent definition is not implemented.
57    #[error("Agent definition \"{0}\" is not implemented")]
58    NotImplemented(String),
59
60    /// An agent with this ID already exists.
61    #[error("Agent {0} already exists")]
62    AgentAlreadyExists(String),
63
64    /// Failed to create an agent.
65    #[error("Failed to create agent {0}")]
66    AgentCreationFailed(String),
67
68    /// Agent with the specified ID was not found.
69    #[error("Agent {0} not found")]
70    AgentNotFound(String),
71
72    /// Source agent in a connection was not found.
73    #[error("Source agent {0} not found")]
74    SourceAgentNotFound(String),
75
76    /// Duplicate ID detected.
77    #[error("Duplicate id: {0}")]
78    DuplicateId(String),
79
80    /// Connection source handle is empty.
81    #[error("Source handle is empty")]
82    EmptySourceHandle,
83
84    /// Connection target handle is empty.
85    #[error("Target handle is empty")]
86    EmptyTargetHandle,
87
88    /// A connection between these ports already exists.
89    #[error("Connection already exists")]
90    ConnectionAlreadyExists,
91
92    /// Connection with the specified ID was not found.
93    #[error("Connection {0} not found")]
94    ConnectionNotFound(String),
95
96    /// Preset with the specified name was not found.
97    #[error("Preset {0} not found")]
98    PresetNotFound(String),
99
100    /// Agent definition was not found.
101    #[error("Agent {0} definition not found")]
102    AgentDefinitionNotFound(String),
103
104    /// Agent message sender was not found.
105    #[error("Agent tx for {0} not found")]
106    AgentTxNotFound(String),
107
108    /// Failed to send a message to an agent.
109    #[error("Failed to send message: {0}")]
110    SendMessageFailed(String),
111
112    /// Serialization or deserialization error.
113    #[error("Failed to serialize/deserialize: {0}")]
114    SerializationError(String),
115
116    /// Message sender is not initialized.
117    #[error("Message sender not initialized")]
118    TxNotInitialized,
119
120    /// I/O error.
121    #[error("IO error: {0}")]
122    IoError(String),
123
124    /// JSON parsing error.
125    #[error("JSON parsing error: {0}")]
126    JsonParseError(String),
127
128    /// Invalid file extension (expected JSON).
129    #[error("Invalid file extension: expected JSON")]
130    InvalidFileExtension,
131
132    /// File name is empty.
133    #[error("Empty file name")]
134    EmptyFileName,
135
136    /// Failed to get file stem from path.
137    #[error("Failed to get file stem from path")]
138    FileSystemError,
139
140    /// Invalid configuration value.
141    #[error("Configuration error: {0}")]
142    InvalidConfig(String),
143
144    /// No configuration is available for this agent.
145    #[error("No configuration available")]
146    NoConfig,
147
148    /// Configuration key does not exist.
149    #[error("Unknown configuration: {0}")]
150    UnknownConfig(String),
151
152    /// No global configuration is available.
153    #[error("No global configuration available")]
154    NoGlobalConfig,
155
156    /// Port (pin) was not found.
157    #[error("Pin not found: {0}")]
158    PinNotFound(String),
159
160    /// Generic agent error.
161    #[error("Agent error: {0}")]
162    Other(String),
163}