Skip to main content

aap_protocol/
errors.rs

1//! AAP error types — all errors have codes AAP-001 through AAP-006.
2
3use thiserror::Error;
4
5/// All AAP errors implement this trait.
6#[derive(Debug, Error)]
7pub enum AAPError {
8    /// AAP-001: Schema validation failed.
9    #[error("AAP-001: validation error on field '{field}': {message}")]
10    Validation { field: String, message: String },
11
12    /// AAP-002: Ed25519 signature verification failed.
13    #[error("AAP-002: signature error: {0}")]
14    Signature(String),
15
16    /// AAP-003: Physical World Rule — Level 4 forbidden for physical nodes.
17    #[error(
18        "AAP-003: Physical World Rule: Autonomous (Level 4) is forbidden \
19         for physical agent '{agent_id}'. Maximum level is Supervised (Level 3). \
20         This rule is not configurable."
21    )]
22    PhysicalWorldViolation { agent_id: String },
23
24    /// AAP-004: Action is outside the agent's authorized scope.
25    #[error("AAP-004: action '{action}' is not in scope for agent '{agent_id}'")]
26    Scope { action: String, agent_id: String },
27
28    /// AAP-005: Identity or authorization has been revoked.
29    #[error("AAP-005: '{id}' has been revoked")]
30    Revocation { id: String },
31
32    /// AAP-006: Audit chain integrity broken.
33    #[error("AAP-006: audit chain broken at entry '{entry_id}'")]
34    Chain { entry_id: String },
35
36    /// Serialization error (internal).
37    #[error("serialization error: {0}")]
38    Serde(#[from] serde_json::Error),
39}
40
41pub type Result<T> = std::result::Result<T, AAPError>;