1use std::fmt;
2use troupekit_ffi_core as neutral;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq, uniffi::Enum)]
8#[repr(u32)]
9pub enum ErrorCode {
10 Config = 1,
11 MissingKey = 2,
12 Catalog = 3,
13 Persona = 4,
14 Agent = 5,
15 Tool = 6,
16 Workflow = 7,
17 Graph = 8,
18 Store = 9,
19 Context = 10,
20 Failed = 11,
21 Paused = 12,
22 Retries = 13,
23 Cancelled = 14,
24 HostCallback = 15,
25 InvalidArgument = 16,
26 Unsupported = 17,
27 Panic = 18,
28 Internal = 99,
29}
30
31#[derive(Clone, Debug, PartialEq, Eq, uniffi::Error)]
37pub enum TroupekitError {
38 Failure {
39 code: u32,
40 detail: String,
41 run_id: Option<String>,
42 },
43}
44
45impl fmt::Display for TroupekitError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 let TroupekitError::Failure { code, detail, .. } = self;
48 write!(f, "troupekit error {code}: {detail}")
49 }
50}
51
52impl std::error::Error for TroupekitError {}
53
54impl From<neutral::FfiError> for TroupekitError {
55 fn from(error: neutral::FfiError) -> Self {
56 TroupekitError::Failure {
57 code: error.code as u32,
58 detail: error.message,
59 run_id: error.run_id,
60 }
61 }
62}
63
64#[derive(Clone, Debug, PartialEq, Eq, uniffi::Error)]
69pub enum HostError {
70 Failed { detail: String },
71}
72
73impl fmt::Display for HostError {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 let HostError::Failed { detail } = self;
76 f.write_str(detail)
77 }
78}
79
80impl std::error::Error for HostError {}
81
82impl From<uniffi::UnexpectedUniFFICallbackError> for HostError {
83 fn from(error: uniffi::UnexpectedUniFFICallbackError) -> Self {
84 HostError::Failed {
85 detail: error.reason,
86 }
87 }
88}
89
90impl From<HostError> for neutral::HostError {
91 fn from(error: HostError) -> Self {
92 let HostError::Failed { detail } = error;
93 neutral::HostError::new(detail)
94 }
95}