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 DTypeMismatch(String),
28 Arithmetic(String),
30}
31
32impl fmt::Display for OnnxError {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 match self {
35 Self::Parse(s) => write!(f, "Parse error: {s}"),
36 Self::UnknownOp(s) => write!(f, "Unknown op: {s}"),
37 Self::ShapeMismatch(s) => write!(f, "Shape mismatch: {s}"),
38 Self::TensorNotFound(s) => write!(f, "Tensor not found: {s}"),
39 Self::Unsupported(s) => write!(f, "Unsupported: {s}"),
40 Self::UnsupportedOp(s) => write!(f, "Unsupported op: {s}"),
41 Self::InvalidModel(s) => write!(f, "Invalid model: {s}"),
42 Self::Internal(s) => write!(f, "Internal error: {s}"),
43 Self::Cancelled(s) => write!(f, "Cancelled: {s}"),
44 Self::DTypeMismatch(s) => write!(f, "DType mismatch: {s}"),
45 Self::Arithmetic(s) => write!(f, "Arithmetic error: {s}"),
46 }
47 }
48}
49
50impl std::error::Error for OnnxError {}
51
52impl From<String> for OnnxError {
53 fn from(s: String) -> Self {
54 Self::Internal(s)
55 }
56}