systemprompt-models 0.64.0

Foundation data models for systemprompt.io AI governance infrastructure. Shared DTOs, config, and domain types consumed by every layer of the MCP governance pipeline.
Documentation
//! Semantic validation errors raised by the services / agents / plugins
//! / hooks / modules validation passes.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

use std::error::Error;
use std::sync::Arc;

#[derive(Debug, Clone, thiserror::Error)]
pub enum ServicesValidationError {
    #[error("{0}")]
    Required(String),

    #[error("{0}")]
    InvalidField(String),

    #[error("{context}: {source}")]
    InvalidFieldCause {
        context: String,
        #[source]
        source: Arc<dyn Error + Send + Sync>,
    },

    #[error("{0}")]
    PortConflict(String),

    #[error("{0}")]
    UnknownReference(String),

    #[error("{0}")]
    CircularDependency(String),

    #[error("{0}")]
    BusinessRule(String),
}

impl ServicesValidationError {
    #[must_use]
    pub fn required(msg: impl Into<String>) -> Self {
        Self::Required(msg.into())
    }

    #[must_use]
    pub fn invalid_field(msg: impl Into<String>) -> Self {
        Self::InvalidField(msg.into())
    }

    #[must_use]
    pub fn invalid_field_cause(
        context: impl Into<String>,
        source: impl Error + Send + Sync + 'static,
    ) -> Self {
        Self::InvalidFieldCause {
            context: context.into(),
            source: Arc::new(source),
        }
    }

    #[must_use]
    pub fn port_conflict(msg: impl Into<String>) -> Self {
        Self::PortConflict(msg.into())
    }

    #[must_use]
    pub fn unknown_reference(msg: impl Into<String>) -> Self {
        Self::UnknownReference(msg.into())
    }

    #[must_use]
    pub fn circular_dependency(msg: impl Into<String>) -> Self {
        Self::CircularDependency(msg.into())
    }

    #[must_use]
    pub fn business_rule(msg: impl Into<String>) -> Self {
        Self::BusinessRule(msg.into())
    }
}