Skip to main content

systemprompt_models/errors/
validation.rs

1//! Semantic validation errors raised by the services / agents / plugins
2//! / hooks / modules validation passes.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7#[derive(Debug, Clone, thiserror::Error)]
8pub enum ConfigValidationError {
9    #[error("{0}")]
10    Required(String),
11
12    #[error("{0}")]
13    InvalidField(String),
14
15    #[error("{0}")]
16    PortConflict(String),
17
18    #[error("{0}")]
19    UnknownReference(String),
20
21    #[error("{0}")]
22    CircularDependency(String),
23
24    #[error("{0}")]
25    BusinessRule(String),
26
27    #[error(
28        "Profile is missing required `system_admin.username`. Set it explicitly or supply the \
29         `SYSTEMPROMPT_SYSTEM_ADMIN` environment variable."
30    )]
31    MissingSystemAdmin,
32}
33
34impl ConfigValidationError {
35    #[must_use]
36    pub fn required(msg: impl Into<String>) -> Self {
37        Self::Required(msg.into())
38    }
39
40    #[must_use]
41    pub fn invalid_field(msg: impl Into<String>) -> Self {
42        Self::InvalidField(msg.into())
43    }
44
45    #[must_use]
46    pub fn port_conflict(msg: impl Into<String>) -> Self {
47        Self::PortConflict(msg.into())
48    }
49
50    #[must_use]
51    pub fn unknown_reference(msg: impl Into<String>) -> Self {
52        Self::UnknownReference(msg.into())
53    }
54
55    #[must_use]
56    pub fn circular_dependency(msg: impl Into<String>) -> Self {
57        Self::CircularDependency(msg.into())
58    }
59
60    #[must_use]
61    pub fn business_rule(msg: impl Into<String>) -> Self {
62        Self::BusinessRule(msg.into())
63    }
64}