1use std::fmt;
4
5#[derive(Debug)]
7pub enum OnnxError {
8 Parse(String),
10 UnknownOp(String),
12 ShapeMismatch(String),
14 TensorNotFound(String),
16 Unsupported(String),
18 UnsupportedOp(String),
20 InvalidModel(String),
22 Internal(String),
24 Cancelled(String),
26}
27
28impl fmt::Display for OnnxError {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::Parse(s) => write!(f, "Parse error: {s}"),
32 Self::UnknownOp(s) => write!(f, "Unknown op: {s}"),
33 Self::ShapeMismatch(s) => write!(f, "Shape mismatch: {s}"),
34 Self::TensorNotFound(s) => write!(f, "Tensor not found: {s}"),
35 Self::Unsupported(s) => write!(f, "Unsupported: {s}"),
36 Self::UnsupportedOp(s) => write!(f, "Unsupported op: {s}"),
37 Self::InvalidModel(s) => write!(f, "Invalid model: {s}"),
38 Self::Internal(s) => write!(f, "Internal error: {s}"),
39 Self::Cancelled(s) => write!(f, "Cancelled: {s}"),
40 }
41 }
42}
43
44impl std::error::Error for OnnxError {}
45
46impl From<String> for OnnxError {
47 fn from(s: String) -> Self {
48 Self::Internal(s)
49 }
50}