1use thiserror::Error;
4
5use crate::diagnostics::RustDiagnostic;
6
7#[derive(Debug, Error, Clone, PartialEq, Eq)]
20pub enum ExecutionError {
21 #[error("unsupported policy: {0}")]
23 UnsupportedPolicy(String),
24
25 #[error("unsupported language: {0}")]
27 UnsupportedLanguage(String),
28
29 #[error("compilation failed: {0}")]
31 CompileFailed(String),
32
33 #[error("execution timeout after {0}ms")]
35 Timeout(u64),
36
37 #[error("execution failed: {0}")]
39 ExecutionFailed(String),
40
41 #[error("rejected: {0}")]
43 Rejected(String),
44
45 #[error("invalid request: {0}")]
47 InvalidRequest(String),
48
49 #[error("internal error: {0}")]
51 InternalError(String),
52}
53
54#[derive(Debug, Clone, Error)]
69pub enum CodeError {
70 #[error("compile error: {stderr}")]
72 CompileError {
73 diagnostics: Vec<RustDiagnostic>,
75 stderr: String,
77 },
78
79 #[error("dependency not found: {name} (searched: {searched:?})")]
81 DependencyNotFound {
82 name: String,
84 searched: Vec<String>,
86 },
87
88 #[error("sandbox error: {0}")]
90 Sandbox(#[from] adk_sandbox::SandboxError),
91
92 #[error("invalid code: {0}")]
94 InvalidCode(String),
95}
96
97impl From<ExecutionError> for adk_core::AdkError {
98 fn from(err: ExecutionError) -> Self {
99 use adk_core::{ErrorCategory, ErrorComponent};
100 let (category, code) = match &err {
101 ExecutionError::UnsupportedPolicy(_) => {
102 (ErrorCategory::Unsupported, "code.unsupported_policy")
103 }
104 ExecutionError::UnsupportedLanguage(_) => {
105 (ErrorCategory::Unsupported, "code.unsupported_language")
106 }
107 ExecutionError::CompileFailed(_) => {
108 (ErrorCategory::InvalidInput, "code.compile_failed")
109 }
110 ExecutionError::Timeout(_) => (ErrorCategory::Timeout, "code.timeout"),
111 ExecutionError::ExecutionFailed(_) => {
112 (ErrorCategory::Internal, "code.execution_failed")
113 }
114 ExecutionError::Rejected(_) => (ErrorCategory::Forbidden, "code.rejected"),
115 ExecutionError::InvalidRequest(_) => {
116 (ErrorCategory::InvalidInput, "code.invalid_request")
117 }
118 ExecutionError::InternalError(_) => (ErrorCategory::Internal, "code.internal"),
119 };
120 adk_core::AdkError::new(ErrorComponent::Code, category, code, err.to_string())
121 .with_source(err)
122 }
123}
124
125impl From<CodeError> for adk_core::AdkError {
126 fn from(err: CodeError) -> Self {
127 use adk_core::{ErrorCategory, ErrorComponent};
128 let (category, code) = match &err {
129 CodeError::CompileError { .. } => (ErrorCategory::InvalidInput, "code.compile_error"),
130 CodeError::DependencyNotFound { .. } => {
131 (ErrorCategory::NotFound, "code.dependency_not_found")
132 }
133 CodeError::Sandbox(_) => (ErrorCategory::Internal, "code.sandbox"),
134 CodeError::InvalidCode(_) => (ErrorCategory::InvalidInput, "code.invalid_code"),
135 };
136 adk_core::AdkError::new(ErrorComponent::Code, category, code, err.to_string())
137 .with_source(err)
138 }
139}