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 #[cfg(all(feature = "onnx", not(target_arch = "wasm32")))]
31 OnnxRuntime(#[from] ort::Error),
32
33 #[error("Runtime error: {0}")]
34 Runtime(String),
35}
36
37impl EdgeError {
38 pub fn model(msg: impl Into<String>) -> Self {
39 Self::Model(msg.into())
40 }
41
42 pub fn inference(msg: impl Into<String>) -> Self {
43 Self::Inference(msg.into())
44 }
45
46 pub fn tokenizer(msg: impl Into<String>) -> Self {
47 Self::Tokenizer(msg.into())
48 }
49
50 pub fn config(msg: impl Into<String>) -> Self {
51 Self::Config(msg.into())
52 }
53
54 pub fn runtime(msg: impl Into<String>) -> Self {
55 Self::Runtime(msg.into())
56 }
57}