use std::path::PathBuf;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid runtime configuration: {0}")]
InvalidConfig(String),
#[error("backend `{backend}` is not compiled; enable the `{feature}` Cargo feature")]
BackendNotCompiled {
backend: &'static str,
feature: &'static str,
},
#[error("backend `{0}` is not available in the linked MNN library")]
BackendUnavailable(&'static str),
#[error("failed to read model `{path}`: {source}")]
ModelRead {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("MNN operation `{operation}` failed: {message}")]
Native {
operation: &'static str,
message: String,
},
#[error("duplicate {kind} tensor `{name}`")]
DuplicateTensor {
kind: &'static str,
name: String,
},
#[error("missing input tensor `{0}`")]
MissingInput(String),
#[error("unknown {kind} tensor `{name}`")]
UnknownTensor {
kind: &'static str,
name: String,
},
#[error("tensor `{name}` shape mismatch: expected {expected:?}, got {actual:?}")]
ShapeMismatch {
name: String,
expected: Vec<i32>,
actual: Vec<usize>,
},
#[error("tensor `{name}` data length mismatch: shape needs {expected} values, got {actual}")]
DataLengthMismatch {
name: String,
expected: usize,
actual: usize,
},
#[error("tensor `{name}` shape is too large")]
ShapeOverflow {
name: String,
},
#[error("tensor `{name}` shape is unresolved; supply concrete input dimensions")]
UnresolvedShape {
name: String,
},
#[error("tensor `{name}` has invalid dimensions {shape:?}")]
InvalidShape {
name: String,
shape: Vec<usize>,
},
#[error("failed to prepare cache directory `{path}`: {source}")]
CacheDirectory {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("model request queue is full")]
QueueFull,
#[error("inference request cancelled")]
Cancelled,
#[error("inference deadline exceeded")]
DeadlineExceeded,
#[error(
"requested {requested} CPU threads, but MNN provides {effective}; initialize the largest thread budget first"
)]
ThreadCountLimited {
requested: usize,
effective: usize,
},
#[error("model worker stopped unexpectedly")]
WorkerStopped,
#[error("model worker panicked during startup")]
WorkerPanicked,
#[error("process-wide MNN execution gate is poisoned")]
ExecutionGatePoisoned,
}