1use thiserror::Error;
4
5pub type EdgeResult<T> = Result<T, EdgeError>;
7
8#[derive(Error, Debug)]
10pub enum EdgeError {
11 #[error("Model error: {0}")]
12 Model(String),
13
14 #[error("Inference error: {0}")]
15 Inference(String),
16
17 #[error("Tokenizer error: {0}")]
18 Tokenizer(String),
19
20 #[error("Configuration error: {0}")]
21 Config(String),
22
23 #[error("I/O error: {0}")]
24 Io(#[from] std::io::Error),
25
26 #[error("JSON error: {0}")]
27 Json(#[from] serde_json::Error),
28
29 #[error("ONNX Runtime error: {0}")]
30 OnnxRuntime(#[from] ort::Error),
31
32 #[error("Runtime error: {0}")]
33 Runtime(String),
34}
35
36impl EdgeError {
37 pub fn model(msg: impl Into<String>) -> Self {
38 Self::Model(msg.into())
39 }
40
41 pub fn inference(msg: impl Into<String>) -> Self {
42 Self::Inference(msg.into())
43 }
44
45 pub fn tokenizer(msg: impl Into<String>) -> Self {
46 Self::Tokenizer(msg.into())
47 }
48
49 pub fn config(msg: impl Into<String>) -> Self {
50 Self::Config(msg.into())
51 }
52
53 pub fn runtime(msg: impl Into<String>) -> Self {
54 Self::Runtime(msg.into())
55 }
56}