1#[cfg(not(target_family = "wasm"))]
7mod model_path;
8
9use std::path::PathBuf;
10
11#[cfg(not(target_family = "wasm"))]
12pub use model_path::{validate_model_directory, validate_model_file};
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct ModelDownload {
17 pub file_name: &'static str,
19 pub url: &'static str,
20 pub bytes: u64,
22 pub sha256: &'static str,
24 pub unpack: Unpack,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum Unpack {
30 Plain,
32 TarBz2Member(&'static str),
34}
35
36#[derive(Debug, thiserror::Error)]
40pub enum BackendError {
41 #[error(transparent)]
42 Engine(Box<dyn std::error::Error + Send + Sync>),
43
44 #[error("the backend answered, but the answer is unusable: {0}")]
45 Unusable(String),
46}
47
48impl BackendError {
49 pub fn engine(error: impl std::error::Error + Send + Sync + 'static) -> Self {
50 Self::Engine(Box::new(error))
51 }
52}
53
54#[derive(Debug, thiserror::Error)]
55pub enum ModelError {
56 #[cfg(not(target_family = "wasm"))]
57 #[error(transparent)]
58 Path(#[from] crate::primitives::file_inspection::InspectionError),
59
60 #[error("failed to read the model directory {}", path.display())]
61 ReadDirectory {
62 path: PathBuf,
63 #[source]
64 source: std::io::Error,
65 },
66
67 #[error("model directory {} is missing {file}", directory.display())]
68 Missing {
69 directory: PathBuf,
70 file: &'static str,
71 },
72
73 #[error("failed to read the model file {}", path.display())]
74 Unreadable {
75 path: PathBuf,
76 #[source]
77 source: std::io::Error,
78 },
79
80 #[error("the model file {} is malformed", path.display())]
81 Malformed {
82 path: PathBuf,
83 #[source]
84 source: Box<dyn std::error::Error + Send + Sync>,
85 },
86}