concision_neural/
error.rs1#[cfg(feature = "alloc")]
11use alloc::{boxed::Box, string::String};
12
13pub type ModelResult<T> = core::result::Result<T, ModelError>;
16
17#[derive(Debug, scsys::VariantConstructors, thiserror::Error)]
25#[non_exhaustive]
26pub enum ModelError {
27 #[error("The model is not initialized")]
29 NotInitialized,
30 #[error("The model is not trained")]
31 NotTrained,
33 #[error("Invalid model configuration")]
34 InvalidModelConfig,
36 #[error("Unsupported model")]
37 UnsupportedModel,
39 #[error("The model is not supported for the given input")]
40 IncompatibleInput,
42 #[error("An unsupported operation was attempted")]
43 UnsupportedOperation,
44 #[error("Invalid Batch Size")]
45 InvalidBatchSize,
46 #[error("Invalid Input Shape")]
47 InvalidInputShape,
48 #[error("Invalid Output Shape")]
49 InvalidOutputShape,
50 #[error(transparent)]
51 TrainingError(#[from] crate::train::TrainingError),
52 #[error(transparent)]
53 CoreError(#[from] concision_core::error::Error),
54 #[cfg(feature = "alloc")]
55 #[error("Parameter Error")]
56 ParameterError(String),
57}
58
59impl From<ModelError> for concision_core::error::Error {
60 fn from(err: ModelError) -> Self {
61 match err {
62 ModelError::CoreError(e) => e,
63 _ => concision_core::error::Error::box_error(err),
64 }
65 }
66}
67
68#[cfg(feature = "alloc")]
69impl From<Box<dyn core::error::Error + Send + Sync>> for ModelError {
70 fn from(err: Box<dyn core::error::Error + Send + Sync>) -> Self {
71 cnc::Error::BoxError(err).into()
72 }
73}
74#[cfg(feature = "alloc")]
75impl From<String> for ModelError {
76 fn from(err: String) -> Self {
77 cnc::Error::unknown(err).into()
78 }
79}
80
81#[cfg(feature = "alloc")]
82impl From<&str> for ModelError {
83 fn from(err: &str) -> Self {
84 cnc::Error::unknown(err).into()
85 }
86}