use std::time::Duration;
#[derive(Debug, thiserror::Error)]
pub enum DataError {
#[error("invalid key: key cannot be empty")]
InvalidKey,
#[error("key not found: {key}")]
KeyNotFound {
key: String,
},
#[error("storage limit exceeded: max {max} entries")]
StorageLimitExceeded {
max: usize,
},
#[error("TTL ({requested:?}) exceeds max ({max:?})")]
TTLExceeded {
requested: Duration,
max: Duration,
},
#[error("value size {size} bytes exceeds max {max} bytes")]
ValueTooLarge {
size: usize,
max: usize,
},
#[error("serialization error: {0}")]
SerializationError(#[from] serde_json::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum ValueMappingError {
#[error("expression construction failed: {0}")]
ExpressionConstruction(#[from] cedar_policy::ExpressionConstructionError),
#[error("type mismatch: expected {expected}, found {actual}")]
TypeMismatch {
expected: String,
actual: String,
},
#[error("invalid {extension_type} format: {value}")]
InvalidExtensionFormat {
extension_type: String,
value: String,
},
#[error("path not found: {path}")]
PathNotFound {
path: String,
},
#[error("invalid path: {path}")]
InvalidPath {
path: String,
},
#[error("null values are not supported in Cedar")]
NullNotSupported,
#[error("invalid entity reference: {reason}")]
InvalidEntityReference {
reason: String,
},
#[error("value size {size} exceeds limit {limit}")]
ValueTooLarge {
size: usize,
limit: usize,
},
#[error("errors in collection: {0:?}")]
CollectionErrors(Vec<ValueMappingError>),
#[error("number cannot be represented in Cedar: {value}")]
NumberNotRepresentable {
value: String,
},
}
#[derive(Debug, thiserror::Error)]
pub enum ValidationError {
#[error("type mismatch at {path}: expected {expected}, found {actual}")]
TypeMismatch {
path: String,
expected: String,
actual: String,
},
#[error("maximum nesting depth ({max}) exceeded at {path}")]
MaxDepthExceeded {
path: String,
max: usize,
},
#[error("string at {path} exceeds maximum length ({length} > {max})")]
StringTooLong {
path: String,
length: usize,
max: usize,
},
#[error("array at {path} exceeds maximum length ({length} > {max})")]
ArrayTooLong {
path: String,
length: usize,
max: usize,
},
#[error("object at {path} has too many keys ({count} > {max})")]
TooManyKeys {
path: String,
count: usize,
max: usize,
},
#[error("null value at {path} is not supported in Cedar")]
NullNotSupported {
path: String,
},
#[error("invalid {extension_type} format at {path}: {value}")]
InvalidExtensionFormat {
path: String,
extension_type: String,
value: String,
},
#[error("invalid entity reference at {path}: {reason}")]
InvalidEntityReference {
path: String,
reason: String,
},
#[error("invalid key at {path}: {reason}")]
InvalidKey {
path: String,
reason: String,
},
#[error("number at {path} is out of i64 range")]
NumberOutOfRange {
path: String,
},
#[error("multiple validation errors: {0:?}")]
Multiple(Vec<ValidationError>),
}