auths_sdk/domains/agents/
error.rs1use auths_core::error::AuthsErrorInfo;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
18#[non_exhaustive]
19pub enum AgentError {
20 #[error("identity not found: {did}")]
22 IdentityNotFound {
23 did: String,
25 },
26
27 #[error("an agent key already exists under alias '{alias}'")]
30 AlreadyDelegated {
31 alias: String,
33 },
34
35 #[error("agent not found: {did}")]
38 AgentNotFound {
39 did: String,
41 },
42
43 #[error("agent {did} is revoked")]
45 Revoked {
46 did: String,
48 },
49
50 #[error("requested capability '{capability}' exceeds the delegator's scope")]
53 OutsideDelegatorScope {
54 capability: String,
56 },
57
58 #[error("crypto error: {0}")]
60 CryptoError(#[source] auths_core::AgentError),
61
62 #[error("agent delegation failed: {0}")]
64 DelegationError(#[source] auths_id::error::InitError),
65
66 #[error("agent delegation attestation failed: {0}")]
69 AttestationError(#[source] auths_verifier::error::AttestationError),
70
71 #[error("agent delegation attestation anchoring failed: {0}")]
73 AnchorError(#[source] auths_id::keri::AnchorError),
74}
75
76impl From<auths_core::AgentError> for AgentError {
77 fn from(err: auths_core::AgentError) -> Self {
78 AgentError::CryptoError(err)
79 }
80}
81
82impl AuthsErrorInfo for AgentError {
83 fn error_code(&self) -> &'static str {
84 match self {
85 Self::IdentityNotFound { .. } => "AUTHS-E5311",
86 Self::AlreadyDelegated { .. } => "AUTHS-E5312",
87 Self::CryptoError(e) => e.error_code(),
88 Self::DelegationError(_) => "AUTHS-E5313",
89 Self::AgentNotFound { .. } => "AUTHS-E5314",
90 Self::Revoked { .. } => "AUTHS-E5315",
91 Self::OutsideDelegatorScope { .. } => "AUTHS-E5316",
92 Self::AttestationError(_) => "AUTHS-E5317",
93 Self::AnchorError(_) => "AUTHS-E5318",
94 }
95 }
96
97 fn suggestion(&self) -> Option<&'static str> {
98 match self {
99 Self::IdentityNotFound { .. } => {
100 Some("Run `auths init` to create a root identity first")
101 }
102 Self::AlreadyDelegated { .. } => {
103 Some("Choose a different --label; run `auths id agent list` to see existing agents")
104 }
105 Self::CryptoError(e) => e.suggestion(),
106 Self::DelegationError(_) => Some(
107 "The agent delegation could not be authored or anchored; check the root identity",
108 ),
109 Self::AgentNotFound { .. } => {
110 Some("Run `auths id agent list` to see the agents this identity has delegated")
111 }
112 Self::Revoked { .. } => {
113 Some("This agent was revoked and cannot be rotated; delegate a new agent instead")
114 }
115 Self::OutsideDelegatorScope { .. } => {
116 Some("Narrow the agent's --scope to a subset of the delegator's own capabilities")
117 }
118 Self::AttestationError(_) => {
119 Some("The delegation attestation could not be signed; check the keychain aliases")
120 }
121 Self::AnchorError(_) => Some(
122 "The delegation attestation could not be anchored; check the root identity's KEL",
123 ),
124 }
125 }
126}