1use serde::Serialize;
2use thiserror::Error;
3
4#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
5pub enum ErrorCode {
6 #[serde(rename = "LOCAL_EXECUTOR_OFFLINE")]
7 LocalExecutorOffline,
8 #[serde(rename = "TOOL_TIMEOUT")]
9 ToolTimeout,
10 #[serde(rename = "CANCELLED")]
11 Cancelled,
12 #[serde(rename = "PATH_ESCAPE")]
13 PathEscape,
14 #[serde(rename = "PATH_NOT_FOUND")]
15 PathNotFound,
16 #[serde(rename = "TOOL_FAILED")]
17 ToolFailed,
18 #[serde(rename = "INVALID_ARGUMENTS")]
19 InvalidArguments,
20 #[serde(rename = "UNKNOWN_TOOL")]
21 UnknownTool,
22 #[serde(rename = "UNKNOWN_PROJECT")]
23 UnknownProject,
24 #[serde(rename = "NO_ACTIVE_PROJECT")]
25 NoActiveProject,
26 #[serde(rename = "FORBIDDEN")]
27 Forbidden,
28 #[serde(rename = "APPROVAL_DECLINED")]
29 ApprovalDeclined,
30 #[serde(rename = "APPROVAL_TIMEOUT")]
31 ApprovalTimeout,
32 #[serde(rename = "INTERNAL_ERROR")]
33 InternalError,
34}
35
36impl ErrorCode {
37 pub const fn as_str(self) -> &'static str {
38 match self {
39 Self::LocalExecutorOffline => "LOCAL_EXECUTOR_OFFLINE",
40 Self::ToolTimeout => "TOOL_TIMEOUT",
41 Self::Cancelled => "CANCELLED",
42 Self::PathEscape => "PATH_ESCAPE",
43 Self::PathNotFound => "PATH_NOT_FOUND",
44 Self::ToolFailed => "TOOL_FAILED",
45 Self::InvalidArguments => "INVALID_ARGUMENTS",
46 Self::UnknownTool => "UNKNOWN_TOOL",
47 Self::UnknownProject => "UNKNOWN_PROJECT",
48 Self::NoActiveProject => "NO_ACTIVE_PROJECT",
49 Self::Forbidden => "FORBIDDEN",
50 Self::ApprovalDeclined => "APPROVAL_DECLINED",
51 Self::ApprovalTimeout => "APPROVAL_TIMEOUT",
52 Self::InternalError => "INTERNAL_ERROR",
53 }
54 }
55}
56
57#[derive(Debug, Error)]
58#[error("{message}")]
59pub struct ExeoraError {
60 pub code: ErrorCode,
61 pub message: String,
62}
63
64impl ExeoraError {
65 pub fn new(code: ErrorCode, message: impl Into<String>) -> Self {
66 Self {
67 code,
68 message: message.into(),
69 }
70 }
71
72 pub fn tool(message: impl Into<String>) -> Self {
73 Self::new(ErrorCode::ToolFailed, message)
74 }
75}