use std::fmt;
use troupekit_ffi_core as neutral;
#[derive(Clone, Copy, Debug, PartialEq, Eq, uniffi::Enum)]
#[repr(u32)]
pub enum ErrorCode {
Config = 1,
MissingKey = 2,
Catalog = 3,
Persona = 4,
Agent = 5,
Tool = 6,
Workflow = 7,
Graph = 8,
Store = 9,
Context = 10,
Failed = 11,
Paused = 12,
Retries = 13,
Cancelled = 14,
HostCallback = 15,
InvalidArgument = 16,
Unsupported = 17,
Panic = 18,
Internal = 99,
}
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Error)]
pub enum TroupekitError {
Failure {
code: u32,
detail: String,
run_id: Option<String>,
},
}
impl fmt::Display for TroupekitError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let TroupekitError::Failure { code, detail, .. } = self;
write!(f, "troupekit error {code}: {detail}")
}
}
impl std::error::Error for TroupekitError {}
impl From<neutral::FfiError> for TroupekitError {
fn from(error: neutral::FfiError) -> Self {
TroupekitError::Failure {
code: error.code as u32,
detail: error.message,
run_id: error.run_id,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, uniffi::Error)]
pub enum HostError {
Failed { detail: String },
}
impl fmt::Display for HostError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let HostError::Failed { detail } = self;
f.write_str(detail)
}
}
impl std::error::Error for HostError {}
impl From<uniffi::UnexpectedUniFFICallbackError> for HostError {
fn from(error: uniffi::UnexpectedUniFFICallbackError) -> Self {
HostError::Failed {
detail: error.reason,
}
}
}
impl From<HostError> for neutral::HostError {
fn from(error: HostError) -> Self {
let HostError::Failed { detail } = error;
neutral::HostError::new(detail)
}
}