Skip to main content

agentic_contract/
error.rs

1//! Error types for AgenticContract.
2
3use thiserror::Error;
4
5/// Errors that can occur in contract operations.
6#[derive(Error, Debug)]
7pub enum ContractError {
8    /// Entity not found by ID.
9    #[error("Contract entity not found: {0}")]
10    NotFound(String),
11
12    /// Policy violation detected.
13    #[error("Policy violation: {0}")]
14    PolicyViolation(String),
15
16    /// Risk limit exceeded.
17    #[error("Risk limit exceeded: {limit} (current: {current}, max: {max})")]
18    RiskLimitExceeded {
19        /// Which limit was exceeded.
20        limit: String,
21        /// Current value.
22        current: f64,
23        /// Maximum allowed.
24        max: f64,
25    },
26
27    /// Approval is required for this action.
28    #[error("Approval required: {0}")]
29    ApprovalRequired(String),
30
31    /// Approval was denied.
32    #[error("Approval denied: {0}")]
33    ApprovalDenied(String),
34
35    /// Condition not met.
36    #[error("Condition not met: {0}")]
37    ConditionNotMet(String),
38
39    /// Obligation unfulfilled.
40    #[error("Obligation unfulfilled: {0}")]
41    ObligationUnfulfilled(String),
42
43    /// Contract has expired.
44    #[error("Contract expired: {0}")]
45    ContractExpired(String),
46
47    /// Invalid contract definition.
48    #[error("Invalid contract: {0}")]
49    InvalidContract(String),
50
51    /// File format error.
52    #[error("File format error: {0}")]
53    FileFormat(String),
54
55    /// IO error.
56    #[error("IO error: {0}")]
57    Io(#[from] std::io::Error),
58
59    /// Serialization error.
60    #[error("Serialization error: {0}")]
61    Serialization(#[from] serde_json::Error),
62}
63
64/// Result type alias for contract operations.
65pub type ContractResult<T> = Result<T, ContractError>;