Skip to main content

inference/
error.rs

1//! Error types for the inference engine.
2
3use thiserror::Error;
4
5/// Errors that can occur during inference operations.
6#[derive(Error, Debug)]
7pub enum InferenceError {
8    /// Model not found or failed to download
9    #[error("Model not found: {0}")]
10    ModelNotFound(String),
11
12    /// Failed to load model weights
13    #[error("Failed to load model: {0}")]
14    ModelLoadError(String),
15
16    /// Tokenization error
17    #[error("Tokenization failed: {0}")]
18    TokenizationError(String),
19
20    /// Inference/forward pass error
21    #[error("Inference failed: {0}")]
22    InferenceError(String),
23
24    /// Invalid input
25    #[error("Invalid input: {0}")]
26    InvalidInput(String),
27
28    /// IO error
29    #[error("IO error: {0}")]
30    IoError(#[from] std::io::Error),
31
32    /// ONNX Runtime error
33    #[error("ONNX Runtime error: {0}")]
34    OrtError(String),
35
36    /// HuggingFace Hub error
37    #[error("HuggingFace Hub error: {0}")]
38    HubError(String),
39
40    /// External extraction provider error (EXT-1)
41    #[error("Extraction failed: {0}")]
42    ExtractionFailed(String),
43}
44
45impl From<ort::Error> for InferenceError {
46    fn from(err: ort::Error) -> Self {
47        InferenceError::OrtError(err.to_string())
48    }
49}
50
51impl From<tokenizers::Error> for InferenceError {
52    fn from(err: tokenizers::Error) -> Self {
53        InferenceError::TokenizationError(err.to_string())
54    }
55}
56
57/// Result type for inference operations.
58pub type Result<T> = std::result::Result<T, InferenceError>;