Skip to main content

json2md/
error.rs

1use std::error::Error as StdError;
2
3use crate::ValidationErrors;
4
5/// The stage that prevents a view from being constructed or rendered.
6///
7/// Dependency diagnostics are available through [`StdError::source`]. Their
8/// types and wording are outside this crate's compatibility contract. Diagnostic
9/// details can contain input values or template text; callers control disclosure.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// The schema is invalid or requires an unavailable external resource.
14    #[error("could not compile JSON Schema")]
15    Schema {
16        /// The validator's diagnostic, including reference-resolution failures.
17        #[source]
18        source: Box<dyn StdError + Send + Sync>,
19    },
20    /// The template cannot be compiled.
21    #[error("could not compile Markdown template")]
22    Template {
23        /// The template engine's syntax diagnostic.
24        #[source]
25        source: Box<dyn StdError + Send + Sync>,
26    },
27    /// The input fails validation; the template does not run.
28    #[error("JSON does not match the view's schema")]
29    Validation(#[from] ValidationErrors),
30    /// Schema-valid input cannot be converted or fails during template execution.
31    #[error("could not render Markdown template")]
32    Render {
33        /// The numeric conversion or template execution diagnostic.
34        #[source]
35        source: Box<dyn StdError + Send + Sync>,
36    },
37}