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("extension `{extension_name}` cancelled the action{}", reason.as_ref().map(|r| format!(": {r}")).unwrap_or_default())]
25 HookCancelled {
26 extension_name: String,
27 reason: Option<String>,
28 },
29
30 #[error("agent loop error: {0}")]
31 AgentLoop(#[from] motosan_agent_loop::AgentError),
32
33 #[error("permissions policy: {0}")]
34 Policy(#[from] crate::permissions::PolicyError),
35
36 #[error("llm error: {0}")]
37 Llm(String),
38}
39
40impl AppError {
41 pub fn io(path: impl Into<PathBuf>, source: io::Error) -> Self {
42 Self::Io {
43 path: path.into(),
44 source,
45 }
46 }
47
48 pub fn tool(tool: impl Into<String>, message: impl Into<String>) -> Self {
49 Self::Tool {
50 tool: tool.into(),
51 message: message.into(),
52 }
53 }
54}