use std::path::PathBuf;
use thiserror::Error;
pub type MlResult<T> = Result<T, MlError>;
#[derive(Debug, Error)]
pub enum MlError {
#[error("device '{0}' is not available in this build")]
DeviceUnavailable(String),
#[error("required feature '{0}' is not enabled (re-build oximedia-ml with --features {0})")]
FeatureDisabled(&'static str),
#[error("failed to load model at {path}: {reason}")]
ModelLoad {
path: PathBuf,
reason: String,
},
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("preprocess error: {0}")]
Preprocess(String),
#[error("postprocess error: {0}")]
Postprocess(String),
#[error("pipeline error ({stage}): {message}")]
Pipeline {
stage: &'static str,
message: String,
},
#[error("model cache capacity must be at least 1")]
CacheCapacityZero,
#[error("onnx runtime error: {0}")]
OnnxRuntime(String),
}
impl MlError {
#[must_use]
pub fn pipeline(stage: &'static str, message: impl Into<String>) -> Self {
Self::Pipeline {
stage,
message: message.into(),
}
}
#[must_use]
pub fn invalid_input(message: impl Into<String>) -> Self {
Self::InvalidInput(message.into())
}
#[must_use]
pub fn preprocess(message: impl Into<String>) -> Self {
Self::Preprocess(message.into())
}
#[must_use]
pub fn postprocess(message: impl Into<String>) -> Self {
Self::Postprocess(message.into())
}
}