combs_mesh/error.rs
1//! Error type shared by every combs-mesh subsystem.
2
3/// The single error type for the crate. Every fallible public API returns
4/// this; readers of external data (binary/unicode/registry) must never
5/// panic, so all malformed-input paths funnel here.
6#[derive(Debug, thiserror::Error)]
7pub enum MeshError {
8 /// Binary container is malformed (bad magic, out-of-bounds directory,
9 /// truncated payload, ...).
10 #[error("format error: {0}")]
11 Format(String),
12 /// A block failed validation (e.g. atlas size does not match pixels).
13 #[error("invalid block: {0}")]
14 InvalidBlock(String),
15 /// A block payload's CRC32 did not match the directory entry.
16 #[error("crc mismatch")]
17 CrcMismatch,
18 /// The binary container version is not supported by this build.
19 #[error("unsupported format version: {0}")]
20 UnsupportedVersion(u16),
21 /// Encryption/decryption failed (wrong key, tampered ciphertext, or a
22 /// key was required but not supplied).
23 #[error("crypto error: {0}")]
24 Crypto(String),
25 /// An operation required the process-wide keyring before `init`.
26 #[error("keyring not initialized")]
27 NotInitialized,
28 /// The Unicode (PUA plane 15/16 + tag char) encoding was malformed.
29 #[error("unicode error: {0}")]
30 Unicode(String),
31 /// Registry (content-addressed store) failure.
32 #[error("registry error: {0}")]
33 Registry(String),
34 /// Filesystem I/O failure.
35 #[error(transparent)]
36 Io(#[from] std::io::Error),
37 /// JSON (de)serialization failure.
38 #[error(transparent)]
39 Json(#[from] serde_json::Error),
40}
41
42/// Convenience alias used across the crate.
43pub type Result<T> = std::result::Result<T, MeshError>;