Skip to main content

antecedent_validate/
error.rs

1//! Validation errors.
2//!
3//! SPDX-License-Identifier: MIT OR Apache-2.0
4
5use antecedent_data::DataError;
6use antecedent_discovery::DiscoveryError;
7use antecedent_estimate::EstimationError;
8use antecedent_prob::ProbError;
9use antecedent_stats::StatsError;
10use thiserror::Error;
11
12/// Validation / refutation failures.
13#[derive(Clone, Debug, Error, Eq, PartialEq)]
14#[non_exhaustive]
15pub enum ValidationError {
16    /// Data transformation failed.
17    #[error(transparent)]
18    Data(#[from] DataError),
19    /// Estimation failed inside a refuter.
20    #[error(transparent)]
21    Estimation(#[from] EstimationError),
22    /// Stats backend failure.
23    #[error(transparent)]
24    Stats(#[from] StatsError),
25    /// Probability / posterior backend.
26    #[error(transparent)]
27    Prob(#[from] ProbError),
28    /// Discovery failure inside a stability check.
29    #[error(transparent)]
30    Discovery(#[from] DiscoveryError),
31    /// Refuter not applicable to the problem.
32    #[error("{message}")]
33    NotApplicable {
34        /// Reason.
35        message: &'static str,
36    },
37}
38
39impl ValidationError {
40    /// Ad-hoc data-layer message.
41    #[must_use]
42    pub fn data_msg(message: impl Into<String>) -> Self {
43        Self::Data(DataError::InvalidArgument { message: message.into() })
44    }
45
46    /// Ad-hoc estimation message.
47    #[must_use]
48    pub fn estimation_msg(message: impl Into<String>) -> Self {
49        Self::Estimation(EstimationError::stats_msg(message))
50    }
51}