Skip to main content

vrm_runtime/
error.rs

1use std::path::PathBuf;
2
3/// Errors raised while loading and parsing a VRM 1.0 avatar.
4#[derive(Debug, thiserror::Error)]
5pub enum LoadError {
6    /// Reading a file or an external buffer/image URI failed.
7    #[error("failed to read `{path}`: {source}")]
8    Io {
9        /// Path that could not be read.
10        path: PathBuf,
11        /// Underlying file-system error.
12        #[source]
13        source: std::io::Error,
14    },
15
16    /// The glTF container or core document is malformed.
17    #[error("glTF parse error: {0}")]
18    Gltf(#[from] gltf::Error),
19
20    /// A VRM extension payload could not be decoded as JSON.
21    #[error("JSON deserialize error: {0}")]
22    Json(#[from] serde_json::Error),
23
24    /// The document declares the unsupported VRM 0.x format.
25    #[error("VRM 0.x specification is not supported. Please use VRM 1.0 (VRMC_VRM) models.")]
26    UnsupportedVrmVersion,
27
28    /// The required top-level `VRMC_vrm` extension is absent.
29    #[error("VRMC_VRM extension missing")]
30    MissingVrmExtension,
31
32    /// The document violates a VRM or supported glTF semantic requirement.
33    #[error("invalid VRM document: {0}")]
34    InvalidVrm(String),
35
36    /// The document requires an extension that this crate cannot evaluate.
37    #[error("required extension `{0}` is not supported")]
38    UnsupportedRequiredExtension(String),
39
40    /// A supported extension object is malformed at a known document location.
41    #[error("invalid `{extension}` extension at {location}: {source}")]
42    InvalidExtension {
43        /// Extension identifier whose payload failed to decode.
44        extension: &'static str,
45        /// JSON-style path to the malformed extension object.
46        location: String,
47        /// Underlying JSON decoding error.
48        #[source]
49        source: serde_json::Error,
50    },
51}
52
53/// Errors raised when a programmatically assembled asset is finalized.
54#[derive(Debug, thiserror::Error)]
55pub enum BuildError {
56    /// The assembled object graph violates an asset invariant.
57    #[error("invalid avatar asset: {0}")]
58    InvalidAsset(String),
59}