Skip to main content

aria_kit/backend/
mod.rs

1//! What every engine backend shares, whichever capability it serves: the
2//! boxed shape of its own failures, and validation of the model files it
3//! loads. Each capability wraps these in its own error vocabulary.
4
5#[cfg(not(target_family = "wasm"))]
6mod model_path;
7
8use std::path::PathBuf;
9
10#[cfg(not(target_family = "wasm"))]
11pub use model_path::{validate_model_directory, validate_model_file};
12
13// The engine's own error stays boxed rather than named. Which engine failed is
14// already on the capability error, and naming the types here would put every
15// engine crate's version in Aria's public API.
16#[derive(Debug, thiserror::Error)]
17pub enum BackendError {
18    #[error(transparent)]
19    Engine(Box<dyn std::error::Error + Send + Sync>),
20
21    #[error("the backend answered, but the answer is unusable: {0}")]
22    Unusable(String),
23}
24
25impl BackendError {
26    pub fn engine(error: impl std::error::Error + Send + Sync + 'static) -> Self {
27        Self::Engine(Box::new(error))
28    }
29}
30
31#[derive(Debug, thiserror::Error)]
32pub enum ModelError {
33    #[cfg(not(target_family = "wasm"))]
34    #[error(transparent)]
35    Path(#[from] crate::primitives::file_inspection::InspectionError),
36
37    #[error("failed to read the model directory {}", path.display())]
38    ReadDirectory {
39        path: PathBuf,
40        #[source]
41        source: std::io::Error,
42    },
43
44    #[error("model directory {} is missing {file}", directory.display())]
45    Missing {
46        directory: PathBuf,
47        file: &'static str,
48    },
49
50    #[error("failed to read the model file {}", path.display())]
51    Unreadable {
52        path: PathBuf,
53        #[source]
54        source: std::io::Error,
55    },
56
57    #[error("the model file {} is malformed", path.display())]
58    Malformed {
59        path: PathBuf,
60        #[source]
61        source: Box<dyn std::error::Error + Send + Sync>,
62    },
63}