assay_registry/canonicalize/
errors.rs1use crate::error::RegistryError;
4
5pub const MAX_DEPTH: usize = 50;
7
8pub const MAX_KEYS_PER_MAPPING: usize = 10_000;
10
11pub const MAX_STRING_LENGTH: usize = 1_024 * 1_024;
13
14pub const MAX_TOTAL_SIZE: usize = 10 * 1_024 * 1_024;
16
17pub const MAX_SAFE_INTEGER: i64 = 9_007_199_254_740_992; pub const MIN_SAFE_INTEGER: i64 = -9_007_199_254_740_992; #[derive(Debug, Clone, PartialEq, Eq)]
25pub enum CanonicalizeError {
26 AnchorFound { position: String },
28
29 AliasFound { position: String },
31
32 TagFound { tag: String },
34
35 MultiDocumentFound,
37
38 DuplicateKey { key: String },
40
41 FloatNotAllowed { value: String },
43
44 IntegerOutOfRange { value: i64 },
46
47 MaxDepthExceeded { depth: usize },
49
50 MaxKeysExceeded { count: usize },
52
53 StringTooLong { length: usize },
55
56 InputTooLarge { size: usize },
58
59 ParseError { message: String },
61
62 SerializeError { message: String },
64}
65
66impl std::fmt::Display for CanonicalizeError {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 match self {
69 Self::AnchorFound { position } => write!(f, "YAML anchor found at {}", position),
70 Self::AliasFound { position } => write!(f, "YAML alias found at {}", position),
71 Self::TagFound { tag } => write!(f, "YAML tag not allowed: {}", tag),
72 Self::MultiDocumentFound => write!(f, "multi-document YAML not allowed"),
73 Self::DuplicateKey { key } => write!(f, "duplicate key: {}", key),
74 Self::FloatNotAllowed { value } => write!(f, "float values not allowed: {}", value),
75 Self::IntegerOutOfRange { value } => {
76 write!(f, "integer {} out of safe range (±2^53)", value)
77 }
78 Self::MaxDepthExceeded { depth } => {
79 write!(f, "nesting depth {} exceeds limit {}", depth, MAX_DEPTH)
80 }
81 Self::MaxKeysExceeded { count } => write!(
82 f,
83 "mapping has {} keys, exceeds limit {}",
84 count, MAX_KEYS_PER_MAPPING
85 ),
86 Self::StringTooLong { length } => write!(
87 f,
88 "string length {} exceeds limit {}",
89 length, MAX_STRING_LENGTH
90 ),
91 Self::InputTooLarge { size } => {
92 write!(f, "input size {} exceeds limit {}", size, MAX_TOTAL_SIZE)
93 }
94 Self::ParseError { message } => write!(f, "YAML parse error: {}", message),
95 Self::SerializeError { message } => write!(f, "JSON serialize error: {}", message),
96 }
97 }
98}
99
100impl std::error::Error for CanonicalizeError {}
101
102pub type CanonicalizeResult<T> = Result<T, CanonicalizeError>;
104
105impl From<CanonicalizeError> for RegistryError {
106 fn from(err: CanonicalizeError) -> Self {
107 RegistryError::InvalidResponse {
108 message: format!(
109 "canonicalization failed (pack invalid/unsupported): {}",
110 err
111 ),
112 }
113 }
114}