Skip to main content

gam_solve/reml/reml_outer_engine/
error.rs

1pub(crate) fn reml_contract_panic(message: impl Into<String>) -> ! {
2    std::panic::panic_any(message.into())
3}
4
5// ═══════════════════════════════════════════════════════════════════════════
6//  Typed errors for the unified REML/LAML evaluator.
7//
8//  The evaluator and its helpers historically returned `Result<_, String>`.
9//  Internally we now build typed errors at the leaves and convert at the
10//  boundary via `From<RemlError> for String`, which is byte-equivalent to
11//  the previous `format!(...)` strings so external callers continue to see
12//  the same diagnostic text.
13// ═══════════════════════════════════════════════════════════════════════════
14
15/// Typed failure categories raised by the unified REML/LAML evaluator and
16/// its outer-Hessian / penalty-root helpers.
17///
18/// Each variant carries a pre-formatted `reason` string so that the
19/// `Display` impl is byte-equivalent to the original `format!(...)` text the
20/// module emitted before the typed-error migration. External signatures
21/// remain `Result<_, String>`; the boundary conversion goes through
22/// `From<RemlError> for String`.
23#[derive(Debug, Clone)]
24pub enum RemlError {
25    /// A length / shape disagreement between two views that should match
26    /// (penalty coords vs Hessian dim, residual length vs operator dim,
27    /// precomputed-correction count vs total, etc.).
28    DimensionMismatch { reason: String },
29    /// A scalar / vector / matrix entry that must be finite came back NaN
30    /// or ±∞ (cost, gradient entry, Hessian entry, cross-trace entry).
31    NonFiniteValue { reason: String },
32    /// A correction path was invoked against an operator kernel that does
33    /// not support it (scalar-only correction on a non-scalar kernel,
34    /// callback correction on a non-callback kernel).
35    InvalidKernelMode { reason: String },
36    /// A caller violated the evaluator contract. These are not numerical
37    /// failures; they mean an upstream solver presented an inner state with
38    /// insufficient certificates for the requested derivative surface.
39    ContractViolation { reason: String },
40}
41
42gam_linalg::impl_reason_error_boilerplate! {
43    RemlError {
44        DimensionMismatch,
45        NonFiniteValue,
46        InvalidKernelMode,
47        ContractViolation,
48    }
49}