1use std::io;
2use std::path::PathBuf;
3
4pub type Result<T, E = AppError> = std::result::Result<T, E>;
5
6#[derive(Debug, thiserror::Error)]
7pub enum AppError {
8 #[error("configuration error: {0}")]
9 Config(String),
10
11 #[error("missing environment variable: {0}")]
12 MissingEnv(String),
13
14 #[error("io error at {path}: {source}")]
15 Io {
16 path: PathBuf,
17 #[source]
18 source: io::Error,
19 },
20
21 #[error("tool '{tool}': {message}")]
22 Tool { tool: String, message: String },
23
24 #[error("agent loop error: {0}")]
25 AgentLoop(#[from] motosan_agent_loop::AgentError),
26
27 #[error("permissions policy: {0}")]
28 Policy(#[from] crate::permissions::PolicyError),
29
30 #[error("llm error: {0}")]
31 Llm(String),
32}
33
34impl AppError {
35 pub fn io(path: impl Into<PathBuf>, source: io::Error) -> Self {
36 Self::Io {
37 path: path.into(),
38 source,
39 }
40 }
41
42 pub fn tool(tool: impl Into<String>, message: impl Into<String>) -> Self {
43 Self::Tool {
44 tool: tool.into(),
45 message: message.into(),
46 }
47 }
48}