Skip to main content

nam_rs/
error.rs

1use thiserror::Error;
2
3/// Errors produced when loading or building a NAM model.
4#[derive(Debug, Error)]
5pub enum Error {
6    /// The `.nam` JSON could not be parsed.
7    #[error("failed to parse .nam JSON: {0}")]
8    Json(#[from] serde_json::Error),
9
10    /// The file was read but its contents are not a valid/supported model.
11    #[error("failed to read .nam file: {0}")]
12    Io(#[from] std::io::Error),
13
14    /// The model's `architecture` field is not one this crate can run.
15    #[error("unsupported model architecture: {0:?}")]
16    UnsupportedArchitecture(String),
17
18    /// A layer's `activation` field names a function this crate does not implement.
19    #[error("unsupported activation function: {0:?}")]
20    UnsupportedActivation(String),
21
22    /// A `.nam` config uses a feature this crate does not yet implement (e.g.
23    /// multi-channel input, a post-stack head with more than one output channel,
24    /// mixed gating modes within one layer array, or an empty container).
25    /// Rejected explicitly rather than silently mis-run — see the crate-level
26    /// docs for the full list of supported and rejected features.
27    #[error("unsupported model feature: {0}")]
28    UnsupportedFeature(String),
29
30    /// The flat `weights` array did not contain the number of values the
31    /// `config` implies (corrupt file, or a config/weights mismatch).
32    #[error("weight count mismatch: config implies {expected} weights, file has {found}")]
33    WeightCountMismatch {
34        /// Number of weights the `config` implies the file must contain.
35        expected: usize,
36        /// Number of weights actually present in the file's flat `weights` array.
37        found: usize,
38    },
39
40    /// The `config`'s declared dimensions are so large that the implied weight
41    /// count overflows `usize`, so the model cannot be built. Indicates a corrupt
42    /// or adversarial file rather than a real capture.
43    #[error("model config dimensions are too large to be valid")]
44    ConfigTooLarge,
45}