kinetic_core/error/
names.rs1use super::Severity;
12use thiserror::Error;
13
14#[derive(Error, Debug, PartialEq, Eq, Clone)]
16pub enum NamesError {
17 #[error("Name is empty or exceeds the 253 character limit")]
19 NameTooLong,
20
21 #[error("Label is empty or exceeds the 63 character limit")]
23 LabelTooLong,
24
25 #[error("Name contains invalid characters (only lowercase letters, digits, and internal hyphens allowed)")]
27 InvalidCharacter,
28
29 #[error("Name is a protected public utility name (e.g., localhost, test)")]
31 ReservedName,
32
33 #[error("Name is a protected infrastructure name (e.g., seed, explorer)")]
35 InfrastructureName,
36
37 #[error("Name has an invalid Top-Level Domain")]
39 InvalidTLD,
40
41 #[error("Only apex names are allowed (subnames must be managed by the apex owner)")]
43 NotAnApexName,
44}
45
46impl NamesError {
47 pub fn code(&self) -> &'static str {
49 match self {
50 Self::NameTooLong => "KIN-NAM-001",
51 Self::LabelTooLong => "KIN-NAM-002",
52 Self::InvalidCharacter => "KIN-NAM-003",
53 Self::ReservedName => "KIN-NAM-004",
54 Self::InfrastructureName => "KIN-NAM-005",
55 Self::InvalidTLD => "KIN-NAM-006",
56 Self::NotAnApexName => "KIN-NAM-007",
57 }
58 }
59
60 pub fn error_type_uri(&self) -> String {
62 format!("{}/errors/{}", crate::constants::DOCS_URL, self.code())
63 }
64
65 pub fn severity(&self) -> Severity {
67 Severity::Warning
68 }
69
70 pub fn is_retryable(&self) -> bool {
72 false
73 }
74
75 pub fn user_message(&self) -> String {
77 match self {
78 Self::NameTooLong => {
79 "The name is empty or exceeds the 253-character limit.".to_string()
80 }
81 Self::LabelTooLong => {
82 "A label within the name exceeds the 63-character limit.".to_string()
83 }
84 Self::InvalidCharacter => {
85 "The name contains invalid characters. Only lowercase letters, digits, and internal hyphens are allowed.".to_string()
86 }
87 Self::ReservedName => {
88 "This name is a permanently protected public utility name.".to_string()
89 }
90 Self::InfrastructureName => {
91 "This name is reserved for critical network infrastructure.".to_string()
92 }
93 Self::InvalidTLD => {
94 "The name does not end with a valid network TLD.".to_string()
95 }
96 Self::NotAnApexName => {
97 "Only apex names (e.g. 'example.kin') can be registered directly.".to_string()
98 }
99 }
100 }
101}