onnx_runtime_optimizer/error.rs
1//! Error types for the optimizer crate.
2//!
3//! Mirrors the two-layer error style of `onnx-runtime-ir`: structural graph
4//! defects surface as [`GraphError`](onnx_runtime_ir::GraphError)s, wrapped
5//! here in the crate-level [`OptimizerError`].
6
7use onnx_runtime_ir::{GraphError, IrError};
8
9/// A convenience `Result` alias for optimizer operations.
10pub type Result<T> = std::result::Result<T, OptimizerError>;
11
12/// Crate-level error for the optimization pipeline.
13#[derive(Debug, thiserror::Error)]
14pub enum OptimizerError {
15 /// A pass left the graph in a structurally invalid state. Raised by the
16 /// default [`OptimizationPass::postconditions`](crate::OptimizationPass::postconditions)
17 /// check (debug builds).
18 #[error("graph invariant violated after pass '{pass}': {errors:?}")]
19 PostconditionFailed {
20 /// The pass whose postcondition failed.
21 pass: String,
22 /// The structural defects found by `graph.validate()`.
23 errors: Vec<GraphError>,
24 },
25
26 /// A rewrite requested an operation the IR rejected.
27 #[error(transparent)]
28 Ir(#[from] IrError),
29
30 /// A fusion could not be applied safely (e.g. malformed match).
31 #[error("fusion '{0}' could not be applied")]
32 Fusion(String),
33}
34
35impl From<Vec<GraphError>> for OptimizerError {
36 fn from(errors: Vec<GraphError>) -> Self {
37 OptimizerError::Ir(IrError::GraphInvalid(errors))
38 }
39}