Skip to main content

rtb_assets/
error.rs

1//! Typed errors for the asset subsystem.
2
3use miette::Diagnostic;
4use thiserror::Error;
5
6/// Failures surfaced by asset access.
7#[derive(Debug, Error, Diagnostic)]
8#[non_exhaustive]
9pub enum AssetError {
10    /// No registered layer had the requested path.
11    #[error("asset not found: {0}")]
12    #[diagnostic(code(rtb::assets::not_found))]
13    NotFound(String),
14
15    /// The requested path exists but its bytes are not valid UTF-8
16    /// (used by `open_text`).
17    #[error("asset `{path}` is not valid UTF-8")]
18    #[diagnostic(code(rtb::assets::not_utf8))]
19    NotUtf8 {
20        /// The offending path.
21        path: String,
22    },
23
24    /// A structured-format parse failed (YAML/JSON/…).
25    #[error("failed to parse asset `{path}` as {format}: {message}")]
26    #[diagnostic(code(rtb::assets::parse), help("verify the file is well-formed {format}"))]
27    Parse {
28        /// The offending path.
29        path: String,
30        /// The expected format (`"YAML"`, `"JSON"`, …).
31        format: &'static str,
32        /// The underlying parser's message.
33        message: String,
34    },
35}