use crate::approx::ApproxError;
use crate::basic::BasicError;
use crate::hom::HomError;
use crate::indec::IndecError;
use crate::supporttau::{PairRejection, SupportTauError};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Endpoint {
Source,
Target,
}
display_error! { Endpoint {
Self::Source => "source";
Self::Target => "target";
} }
#[derive(Clone, Debug)]
pub enum MutationDefect {
AlmostCompleteRejected(PairRejection),
TargetRejected(PairRejection),
DroppedVertexCount {
dropped: Vec<u32>,
},
CokernelNonzero {
dim_vector: Vec<usize>,
},
CokernelZero,
CokernelSummandsDiffer {
summand: usize,
},
ReplacementRepeatsSummand {
summand: usize,
},
AddClosureMissing {
endpoint: Endpoint,
},
ProjectiveSupportNotExtended {
endpoint: Endpoint,
},
EndpointsIsomorphic,
}
display_error! { error MutationDefect {
Self::AlmostCompleteRejected(rejection) => "dropping the slot summand left condition {} unmet: {rejection}; crate defect", rejection.condition();
Self::TargetRejected(rejection) => "the built pair left condition {} unmet: {rejection}; crate defect", rejection.condition();
Self::DroppedVertexCount { dropped } => "dropping the slot summand lost {} vertices, not one; crate defect", dropped.len();
Self::CokernelNonzero { dim_vector } => "the approximation has cokernel of dimension vector {dim_vector:?} where the \
support test says zero; crate defect";
Self::CokernelZero => "the approximation has zero cokernel where the support test says nonzero; \
crate defect";
Self::CokernelSummandsDiffer { summand } => "cokernel summand {summand} is not isomorphic to the first one; crate defect";
Self::ReplacementRepeatsSummand { summand } => "the cokernel summand repeats summand {summand} of the module part; crate defect";
Self::AddClosureMissing { endpoint } => "the {endpoint} pair does not contain U; crate defect";
Self::ProjectiveSupportNotExtended { endpoint } => "the {endpoint} projective support does not contain Q; crate defect";
Self::EndpointsIsomorphic => "the two completions are isomorphic; crate defect";
} }
#[derive(Clone, Debug)]
pub enum MutationError {
SlotOutOfRange {
slot: usize,
summands: usize,
},
SummandIndexCount {
indices: usize,
summands: usize,
},
Basic(BasicError),
SupportTau(SupportTauError),
Approx(ApproxError),
Hom(HomError),
Indec(IndecError),
Defect(MutationDefect),
}
display_error! { MutationError {
Self::SlotOutOfRange { slot, summands } => "slot {slot} is out of range, the module part has {summands} summands";
Self::SummandIndexCount { indices, summands } => "{indices} summand indices for {summands} summands";
Self::Basic(error) => "basic layer: {error}";
Self::SupportTau(error) => "support tau-tilting layer: {error}";
Self::Approx(error) => "approximation layer: {error}";
Self::Hom(error) => "hom: {error}";
Self::Indec(error) => "cokernel summand: {error}";
Self::Defect(defect) => "{defect}";
} }
error_source!(MutationError {
Self::Basic(error) => Some(error),
Self::SupportTau(error) => Some(error),
Self::Approx(error) => Some(error),
Self::Hom(error) => Some(error),
Self::Indec(error) => Some(error),
Self::Defect(defect) => Some(defect),
Self::SlotOutOfRange { .. } | Self::SummandIndexCount { .. } => None,
});
from_variants!(MutationError {
BasicError => Basic,
SupportTauError => SupportTau,
HomError => Hom,
});
pub(super) fn defect(defect: MutationDefect) -> MutationError {
MutationError::Defect(defect)
}