1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
7#[allow(missing_docs)] pub enum BamlSysError {
9 #[error("BAML library not found. Searched paths: {searched_paths:?}")]
11 LibraryNotFound { searched_paths: Vec<PathBuf> },
12
13 #[error("Failed to load BAML library from {path}: {source}")]
15 LoadFailed {
16 path: PathBuf,
17 #[source]
18 source: libloading::Error,
19 },
20
21 #[error("Symbol '{symbol}' not found in BAML library: {source}")]
23 SymbolNotFound {
24 symbol: &'static str,
25 #[source]
26 source: libloading::Error,
27 },
28
29 #[error("Version mismatch: Rust package expects {expected}, but library reports {actual}")]
31 VersionMismatch { expected: String, actual: String },
32
33 #[error("Platform not supported: {os}/{arch}")]
35 UnsupportedPlatform {
36 os: &'static str,
37 arch: &'static str,
38 },
39
40 #[error("Failed to determine cache directory: {0}")]
42 CacheDir(String),
43
44 #[error("Failed to download library: {0}")]
46 DownloadFailed(String),
47
48 #[error("Checksum mismatch: expected {expected}, got {actual}")]
50 ChecksumMismatch { expected: String, actual: String },
51
52 #[error("IO error: {0}")]
54 Io(#[from] std::io::Error),
55
56 #[error("Library already initialized from {existing_path}, cannot change to {requested_path}")]
58 AlreadyInitialized {
59 existing_path: PathBuf,
60 requested_path: PathBuf,
61 },
62}
63
64pub type Result<T> = std::result::Result<T, BamlSysError>;