systemprompt_models/errors/
validation.rs1use std::error::Error;
8use std::sync::Arc;
9
10#[derive(Debug, Clone, thiserror::Error)]
11pub enum ServicesValidationError {
12 #[error("{0}")]
13 Required(String),
14
15 #[error("{0}")]
16 InvalidField(String),
17
18 #[error("{context}: {source}")]
19 InvalidFieldCause {
20 context: String,
21 #[source]
22 source: Arc<dyn Error + Send + Sync>,
23 },
24
25 #[error("{0}")]
26 PortConflict(String),
27
28 #[error("{0}")]
29 UnknownReference(String),
30
31 #[error("{0}")]
32 CircularDependency(String),
33
34 #[error("{0}")]
35 BusinessRule(String),
36}
37
38impl ServicesValidationError {
39 #[must_use]
40 pub fn required(msg: impl Into<String>) -> Self {
41 Self::Required(msg.into())
42 }
43
44 #[must_use]
45 pub fn invalid_field(msg: impl Into<String>) -> Self {
46 Self::InvalidField(msg.into())
47 }
48
49 #[must_use]
50 pub fn invalid_field_cause(
51 context: impl Into<String>,
52 source: impl Error + Send + Sync + 'static,
53 ) -> Self {
54 Self::InvalidFieldCause {
55 context: context.into(),
56 source: Arc::new(source),
57 }
58 }
59
60 #[must_use]
61 pub fn port_conflict(msg: impl Into<String>) -> Self {
62 Self::PortConflict(msg.into())
63 }
64
65 #[must_use]
66 pub fn unknown_reference(msg: impl Into<String>) -> Self {
67 Self::UnknownReference(msg.into())
68 }
69
70 #[must_use]
71 pub fn circular_dependency(msg: impl Into<String>) -> Self {
72 Self::CircularDependency(msg.into())
73 }
74
75 #[must_use]
76 pub fn business_rule(msg: impl Into<String>) -> Self {
77 Self::BusinessRule(msg.into())
78 }
79}