Skip to main content

onnx_std/
error.rs

1//! Error types for the `onnx-std` public API.
2//!
3//! `onnx-std` wraps the runtime's [`onnx_runtime_loader`] pipeline for the actual
4//! protobuf parsing/encoding, so most failures surface as a wrapped
5//! [`LoaderError`]. The extra variants capture the file-system framing that the
6//! ergonomic [`crate::load_model`] / [`crate::save_model`] entry points add on
7//! top.
8
9use std::path::PathBuf;
10
11use onnx_runtime_loader::LoaderError;
12
13/// The result type used throughout the `onnx-std` public API.
14pub type Result<T> = std::result::Result<T, Error>;
15
16/// An error produced by an `onnx-std` operation.
17#[derive(Debug, thiserror::Error)]
18pub enum Error {
19    /// Reading the model file from disk failed.
20    #[error("failed to read model file {path}: {source}")]
21    Read {
22        /// The path that could not be read.
23        path: PathBuf,
24        /// The underlying I/O error.
25        #[source]
26        source: std::io::Error,
27    },
28
29    /// Writing the model file to disk failed.
30    #[error("failed to write model file {path}: {source}")]
31    Write {
32        /// The path that could not be written.
33        path: PathBuf,
34        /// The underlying I/O error.
35        #[source]
36        source: std::io::Error,
37    },
38
39    /// The underlying loader (parse / build / encode) failed.
40    #[error(transparent)]
41    Loader(#[from] LoaderError),
42
43    /// A textual ONNX model could not be parsed.
44    #[error("text parse error at line {line}: {message}")]
45    TextParse {
46        /// One-based source line containing the error.
47        line: usize,
48        /// Human-readable description of the malformed construct.
49        message: String,
50    },
51
52    /// An ONNX protobuf-JSON document could not be encoded or decoded.
53    #[error("ONNX JSON error: {0}")]
54    Json(String),
55
56    /// An ONNX protobuf TextFormat document could not be encoded or decoded.
57    #[error("ONNX TextProto error: {0}")]
58    TextProto(String),
59}