use crate::daemon::ErrorCode;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum ValidationError {
#[error("{message} requires one of: {expected}")]
MissingTarget {
message: &'static str,
expected: &'static str,
},
#[error("{message} accepts only one of: {expected}")]
AmbiguousTarget {
message: &'static str,
expected: &'static str,
},
#[error("{field} is not a drawable rect: width and height must be finite and positive")]
InvalidRect {
field: &'static str,
},
#[error("{field} contains a non-finite coordinate")]
NonFiniteCoordinate {
field: &'static str,
},
#[error("{field} must not be empty")]
Empty {
field: &'static str,
},
#[error("path needs at least 2 points, got {got}")]
PathTooShort {
got: usize,
},
#[error("{got:?} is not a position: use a name like `top-left`, or `50%,30%`")]
UnknownPosition {
got: String,
},
#[error("{got} is outside the display: a percentage must be between 0% and 100%")]
PositionOutOfRange {
got: String,
},
#[error("ttl_ms must be greater than zero, or omitted to draw until cleared")]
ZeroTtl,
}
impl ValidationError {
pub const fn code(&self) -> ErrorCode {
ErrorCode::BadSchema
}
}
pub trait Validate {
fn validate(&self) -> Result<(), ValidationError>;
}