ubl_office/
errors.rs

1//! Office errors.
2
3use thiserror::Error;
4
5/// Errors from the Office runtime.
6#[derive(Debug, Error)]
7pub enum OfficeError {
8    /// Cognition error (brain failure).
9    #[error("cognition error: {0}")]
10    Brain(String),
11    /// Policy gate error.
12    #[error("policy gate error: {0}")]
13    Gate(String),
14    /// Policy violation — action blocked by Gate.
15    #[error("policy violation: {0}")]
16    PolicyViolation(String),
17    /// Tool execution error.
18    #[error("tool execution error: {0}")]
19    Tool(String),
20    /// IO error.
21    #[error("io error: {0}")]
22    Io(String),
23    /// Configuration error.
24    #[error("config error: {0}")]
25    Config(String),
26    /// Context window exceeded.
27    #[error("context overflow: {0}")]
28    ContextOverflow(String),
29    /// Quota exceeded (tokens, decisions, daily limit).
30    #[error("quota exceeded: {0}")]
31    QuotaExceeded(String),
32    /// Ledger append failed.
33    #[error("ledger error: {0}")]
34    Ledger(String),
35    /// Provider error (LLM API).
36    #[error("provider error: {0}")]
37    Provider(String),
38    /// Shutdown requested.
39    #[error("shutdown requested")]
40    Shutdown,
41}
42
43impl From<std::io::Error> for OfficeError {
44    fn from(e: std::io::Error) -> Self {
45        Self::Io(e.to_string())
46    }
47}
48
49impl From<tdln_brain::BrainError> for OfficeError {
50    fn from(e: tdln_brain::BrainError) -> Self {
51        match e {
52            tdln_brain::BrainError::ContextOverflow => {
53                Self::ContextOverflow("brain context overflow".into())
54            }
55            tdln_brain::BrainError::Provider(msg) => Self::Provider(msg),
56            other => Self::Brain(other.to_string()),
57        }
58    }
59}
60
61impl From<ubl_mcp::McpError> for OfficeError {
62    fn from(e: ubl_mcp::McpError) -> Self {
63        match e {
64            ubl_mcp::McpError::PolicyViolation(msg) => Self::PolicyViolation(msg),
65            other => Self::Tool(other.to_string()),
66        }
67    }
68}