Skip to main content

gamlss_formula/
error.rs

1use gamlss_core::ModelError;
2use gamlss_spline::{FourierError, SplineError};
3use thiserror::Error;
4
5/// Errors returned by the typed formula/builder layer.
6#[derive(Debug, Clone, PartialEq, Error)]
7pub enum FormulaError {
8    /// Requested column is not available in the data view.
9    #[error("unknown column `{0}`")]
10    UnknownColumn(String),
11
12    /// A column returned by [`crate::DataView`] has a length different from
13    /// [`crate::DataView::nrows`].
14    #[error("column `{name}` has {actual} rows, expected {expected}")]
15    ColumnLength {
16        /// Column name.
17        name: String,
18        /// Expected number of rows.
19        expected: usize,
20        /// Actual number of rows.
21        actual: usize,
22    },
23
24    /// Requested column type is not supported by this data view.
25    #[error("column `{name}` does not support requested type `{requested}`")]
26    UnsupportedColumnType {
27        /// Column name.
28        name: String,
29        /// Requested logical type.
30        requested: &'static str,
31    },
32
33    /// Numeric input contains a non-finite value.
34    #[error("column `{name}` contains non-finite value at row {row}")]
35    NonFiniteValue {
36        /// Column name.
37        name: String,
38        /// Row index.
39        row: usize,
40    },
41
42    /// Observation weight is not finite or is negative.
43    #[error("weights column `{name}` has invalid value at row {row}")]
44    InvalidWeight {
45        /// Column name.
46        name: String,
47        /// Row index.
48        row: usize,
49    },
50
51    /// Response value is outside the family domain.
52    #[error("response column `{name}` has invalid {family} value at row {row}")]
53    InvalidResponseDomain {
54        /// Column name.
55        name: String,
56        /// Family name.
57        family: &'static str,
58        /// Row index.
59        row: usize,
60    },
61
62    /// Prediction data contains a categorical level not seen during training.
63    #[error("column `{name}` has unknown category `{level}` at row {row}")]
64    UnknownCategoryLevel {
65        /// Column name.
66        name: String,
67        /// Unknown level.
68        level: String,
69        /// Row index.
70        row: usize,
71    },
72
73    /// The model spec did not include a response column.
74    #[error("model spec is missing a response column")]
75    MissingResponse,
76
77    /// The data view has no rows.
78    #[error("data view must contain at least one row")]
79    EmptyData,
80
81    /// A model parameter was configured more than once.
82    #[error("parameter `{0}` terms were specified more than once")]
83    DuplicateParameter(&'static str),
84
85    /// Spline term construction failed.
86    #[error(transparent)]
87    Spline(#[from] SplineError),
88
89    /// Fourier term construction failed.
90    #[error(transparent)]
91    Fourier(#[from] FourierError),
92
93    /// Compiled core model validation failed.
94    #[error(transparent)]
95    Model(#[from] ModelError),
96}