Skip to main content

onnx_export_rs/
error.rs

1//! Error types.
2
3use std::path::PathBuf;
4
5/// Errors returned while constructing, encoding, or validating a model.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// The supplied canonical model is inconsistent.
9    #[error("invalid model: {0}")]
10    InvalidModel(String),
11    /// ONNX serialization failed.
12    #[error("failed to encode ONNX model: {0}")]
13    Encode(#[from] prost::EncodeError),
14    /// A model file could not be written.
15    #[error("failed to write ONNX model to {path}: {source}")]
16    Io {
17        /// Destination path.
18        path: PathBuf,
19        /// Underlying I/O error.
20        source: std::io::Error,
21    },
22    /// Loading or running a model in the validation runtime failed.
23    #[cfg(feature = "validate")]
24    #[error("ONNX validation runtime failed: {0}")]
25    Validation(String),
26}
27
28/// Crate-wide result type.
29pub type Result<T> = std::result::Result<T, Error>;