kinetic_core/error/
dns.rs1use super::Severity;
9use thiserror::Error;
10
11#[derive(Error, Debug)]
13pub enum DnsError {
14 #[error("Payload rejected: JSON nested too deeply")]
16 NestedTooDeeply,
17
18 #[error("Failed to parse DNS zone: {0}")]
20 ParseError(#[from] serde_json::Error),
21
22 #[error("Maximum of 50 DNS records allowed per zone to prevent network bloat")]
24 TooManyRecords,
25
26 #[error("Invalid label length: {0}")]
28 InvalidLabelLength(String),
29
30 #[error("Invalid label character: {0}")]
32 InvalidLabelCharacters(String),
33
34 #[error("CNAME record for '{0}' must be the only record")]
36 InvalidCnameConfiguration(String),
37
38 #[error("TXT record too long for label {0}")]
40 TxtRecordTooLong(String),
41
42 #[error("CNAME target length invalid for label {0}")]
44 InvalidCnameTarget(String),
45
46 #[error("Invalid PeerId string: {0}")]
48 InvalidPeerId(String),
49
50 #[error("Invalid KID string (missing prefix): {0}")]
52 InvalidKid(String),
53
54 #[error("Invalid IPFS CID string: {0}")]
56 InvalidIpfsCid(String),
57}
58
59impl PartialEq for DnsError {
60 fn eq(&self, other: &Self) -> bool {
61 match (self, other) {
62 (Self::NestedTooDeeply, Self::NestedTooDeeply) => true,
63 (Self::ParseError(a), Self::ParseError(b)) => a.to_string() == b.to_string(),
64 (Self::TooManyRecords, Self::TooManyRecords) => true,
65 (Self::InvalidLabelLength(a), Self::InvalidLabelLength(b)) => a == b,
66 (Self::InvalidLabelCharacters(a), Self::InvalidLabelCharacters(b)) => a == b,
67 (Self::InvalidCnameConfiguration(a), Self::InvalidCnameConfiguration(b)) => a == b,
68 (Self::TxtRecordTooLong(a), Self::TxtRecordTooLong(b)) => a == b,
69 (Self::InvalidCnameTarget(a), Self::InvalidCnameTarget(b)) => a == b,
70 (Self::InvalidPeerId(a), Self::InvalidPeerId(b)) => a == b,
71 (Self::InvalidKid(a), Self::InvalidKid(b)) => a == b,
72 (Self::InvalidIpfsCid(a), Self::InvalidIpfsCid(b)) => a == b,
73 _ => false,
74 }
75 }
76}
77
78impl Eq for DnsError {}
79
80impl DnsError {
81 pub fn code(&self) -> &'static str {
83 match self {
84 Self::NestedTooDeeply => "KIN-DNS-001",
85 Self::ParseError(_) => "KIN-DNS-002",
86 Self::TooManyRecords => "KIN-DNS-003",
87 Self::InvalidLabelLength(_) => "KIN-DNS-004",
88 Self::InvalidLabelCharacters(_) => "KIN-DNS-005",
89 Self::InvalidCnameConfiguration(_) => "KIN-DNS-006",
90 Self::TxtRecordTooLong(_) => "KIN-DNS-007",
91 Self::InvalidCnameTarget(_) => "KIN-DNS-008",
92 Self::InvalidPeerId(_) => "KIN-DNS-009",
93 Self::InvalidKid(_) => "KIN-DNS-010",
94 Self::InvalidIpfsCid(_) => "KIN-DNS-011",
95 }
96 }
97
98 pub fn error_type_uri(&self) -> String {
100 format!("{}/errors/{}", crate::constants::DOCS_URL, self.code())
101 }
102
103 pub fn severity(&self) -> Severity {
105 Severity::Warning
107 }
108
109 pub fn is_retryable(&self) -> bool {
111 false }
113
114 pub fn user_message(&self) -> String {
116 match self {
117 Self::NestedTooDeeply => {
118 "The DNS zone contains data that is nested too deeply.".to_string()
119 }
120 Self::ParseError(_) => "Failed to parse the DNS zone data.".to_string(),
121 Self::TooManyRecords => {
122 "The DNS zone contains too many records (maximum 50).".to_string()
123 }
124 Self::InvalidLabelLength(_) => "A DNS record label has an invalid length.".to_string(),
125 Self::InvalidLabelCharacters(_) => {
126 "A DNS record label contains invalid characters.".to_string()
127 }
128 Self::InvalidCnameConfiguration(_) => {
129 "A CNAME record must be the only record for its label.".to_string()
130 }
131 Self::TxtRecordTooLong(_) => {
132 "A TXT record is too long (maximum 255 bytes).".to_string()
133 }
134 Self::InvalidCnameTarget(_) => "A CNAME target is invalid or too long.".to_string(),
135 Self::InvalidPeerId(_) => "A PeerId string is invalid.".to_string(),
136 Self::InvalidKid(_) => {
137 "A KID string is invalid or missing the 'did:kin:' prefix.".to_string()
138 }
139 Self::InvalidIpfsCid(_) => "An IPFS CID string is invalid.".to_string(),
140 }
141 }
142}