nt_neural/
error.rs

1//! Error types for the neural module
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum NeuralError {
7    #[cfg(feature = "candle")]
8    #[error("Candle error: {0}")]
9    Candle(#[from] candle_core::Error),
10
11    #[error("IO error: {0}")]
12    Io(#[from] std::io::Error),
13
14    #[error("JSON error: {0}")]
15    Json(#[from] serde_json::Error),
16
17    #[error("Model error: {0}")]
18    Model(String),
19
20    #[error("Training error: {0}")]
21    Training(String),
22
23    #[error("Inference error: {0}")]
24    Inference(String),
25
26    #[error("Data error: {0}")]
27    Data(String),
28
29    #[error("Configuration error: {0}")]
30    Config(String),
31
32    #[error("Device error: {0}")]
33    Device(String),
34
35    #[error("Checkpoint error: {0}")]
36    Checkpoint(String),
37
38    #[error("Storage error: {0}")]
39    Storage(String),
40
41    #[error("Feature not available: {0}")]
42    NotImplemented(String),
43}
44
45pub type Result<T> = std::result::Result<T, NeuralError>;
46
47impl NeuralError {
48    pub fn model(msg: impl Into<String>) -> Self {
49        Self::Model(msg.into())
50    }
51
52    pub fn training(msg: impl Into<String>) -> Self {
53        Self::Training(msg.into())
54    }
55
56    pub fn inference(msg: impl Into<String>) -> Self {
57        Self::Inference(msg.into())
58    }
59
60    pub fn data(msg: impl Into<String>) -> Self {
61        Self::Data(msg.into())
62    }
63
64    pub fn config(msg: impl Into<String>) -> Self {
65        Self::Config(msg.into())
66    }
67
68    pub fn device(msg: impl Into<String>) -> Self {
69        Self::Device(msg.into())
70    }
71
72    pub fn not_implemented(msg: impl Into<String>) -> Self {
73        Self::NotImplemented(msg.into())
74    }
75
76    pub fn io(msg: impl Into<String>) -> Self {
77        Self::Io(std::io::Error::other(msg.into()))
78    }
79
80    pub fn storage(msg: impl Into<String>) -> Self {
81        Self::Storage(msg.into())
82    }
83}