use thiserror::Error;
#[derive(Debug, Error)]
pub enum OfficeError {
#[error("cognition error: {0}")]
Brain(String),
#[error("policy gate error: {0}")]
Gate(String),
#[error("policy violation: {0}")]
PolicyViolation(String),
#[error("tool execution error: {0}")]
Tool(String),
#[error("io error: {0}")]
Io(String),
#[error("config error: {0}")]
Config(String),
#[error("context overflow: {0}")]
ContextOverflow(String),
#[error("quota exceeded: {0}")]
QuotaExceeded(String),
#[error("ledger error: {0}")]
Ledger(String),
#[error("provider error: {0}")]
Provider(String),
#[error("shutdown requested")]
Shutdown,
}
impl From<std::io::Error> for OfficeError {
fn from(e: std::io::Error) -> Self {
Self::Io(e.to_string())
}
}
impl From<tdln_brain::BrainError> for OfficeError {
fn from(e: tdln_brain::BrainError) -> Self {
match e {
tdln_brain::BrainError::ContextOverflow => {
Self::ContextOverflow("brain context overflow".into())
}
tdln_brain::BrainError::Provider(msg) => Self::Provider(msg),
other => Self::Brain(other.to_string()),
}
}
}
impl From<ubl_mcp::McpError> for OfficeError {
fn from(e: ubl_mcp::McpError) -> Self {
match e {
ubl_mcp::McpError::PolicyViolation(msg) => Self::PolicyViolation(msg),
other => Self::Tool(other.to_string()),
}
}
}