Skip to main content

systemprompt_content/models/
content_error.rs

1//! Content validation error types.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6#[derive(Debug, thiserror::Error)]
7pub enum ContentValidationError {
8    #[error("Missing required field: {field}")]
9    MissingField { field: String },
10
11    #[error(
12        "Missing organization config: '{field}' in content.yaml under \
13         metadata.structured_data.organization"
14    )]
15    MissingOrgConfig { field: String },
16
17    #[error(
18        "Missing article config: '{field}' in content.yaml under metadata.structured_data.article"
19    )]
20    MissingArticleConfig { field: String },
21
22    #[error("Invalid content: {message}")]
23    InvalidContent { message: String },
24
25    #[error("Missing branding config: '{field}' in web.yaml under branding")]
26    MissingBrandingConfig { field: String },
27}
28
29impl ContentValidationError {
30    pub fn missing_field(field: impl Into<String>) -> Self {
31        Self::MissingField {
32            field: field.into(),
33        }
34    }
35
36    pub fn missing_org_config(field: impl Into<String>) -> Self {
37        Self::MissingOrgConfig {
38            field: field.into(),
39        }
40    }
41
42    pub fn missing_article_config(field: impl Into<String>) -> Self {
43        Self::MissingArticleConfig {
44            field: field.into(),
45        }
46    }
47
48    pub fn invalid_content(message: impl Into<String>) -> Self {
49        Self::InvalidContent {
50            message: message.into(),
51        }
52    }
53
54    pub fn missing_branding_config(field: impl Into<String>) -> Self {
55        Self::MissingBrandingConfig {
56            field: field.into(),
57        }
58    }
59}