1use super::*;
2use std::error::Error;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum CmsModelError {
6 EmptyField { field: &'static str },
7 InvalidToken { field: &'static str, value: String },
8 InvalidPath { field: &'static str, value: String },
9 DataPlan { error: DataModelError },
10 MissingLiveRevision { page_id: String },
11 CannotScheduleInThePast { publish_at: u64, now: u64 },
12 NavigationCycle { item_id: String },
13 DuplicateNavigationItem { item_id: String },
14}
15
16impl fmt::Display for CmsModelError {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::EmptyField { field } => write!(f, "`{field}` cannot be empty"),
20 Self::InvalidToken { field, value } => {
21 write!(f, "`{field}` contains an invalid token `{value}`")
22 }
23 Self::InvalidPath { field, value } => {
24 write!(f, "`{field}` must start with `/`, got `{value}`")
25 }
26 Self::DataPlan { error } => write!(f, "{error}"),
27 Self::MissingLiveRevision { page_id } => {
28 write!(f, "page `{page_id}` has no live revision")
29 }
30 Self::CannotScheduleInThePast { publish_at, now } => write!(
31 f,
32 "scheduled publish time `{publish_at}` must be greater than current time `{now}`"
33 ),
34 Self::NavigationCycle { item_id } => {
35 write!(f, "navigation item `{item_id}` introduces a cycle")
36 }
37 Self::DuplicateNavigationItem { item_id } => {
38 write!(f, "navigation item `{item_id}` is duplicated in the tree")
39 }
40 }
41 }
42}
43
44impl Error for CmsModelError {}
45
46impl From<DataModelError> for CmsModelError {
47 fn from(error: DataModelError) -> Self {
48 Self::DataPlan { error }
49 }
50}