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)]
14pub enum ValidationError {
15    /// Data transformation failed.
16    #[error(transparent)]
17    Data(#[from] DataError),
18    /// Estimation failed inside a refuter.
19    #[error(transparent)]
20    Estimation(#[from] EstimationError),
21    /// Stats backend failure.
22    #[error(transparent)]
23    Stats(#[from] StatsError),
24    /// Probability / posterior backend.
25    #[error(transparent)]
26    Prob(#[from] ProbError),
27    /// Discovery failure inside a stability check.
28    #[error(transparent)]
29    Discovery(#[from] DiscoveryError),
30    /// Refuter not applicable to the problem.
31    #[error("{message}")]
32    NotApplicable {
33        /// Reason.
34        message: &'static str,
35    },
36}
37
38impl ValidationError {
39    /// Ad-hoc data-layer message.
40    #[must_use]
41    pub fn data_msg(message: impl Into<String>) -> Self {
42        Self::Data(DataError::InvalidArgument { message: message.into() })
43    }
44
45    /// Ad-hoc estimation message.
46    #[must_use]
47    pub fn estimation_msg(message: impl Into<String>) -> Self {
48        Self::Estimation(EstimationError::stats_msg(message))
49    }
50}