ephemeris_documents/error/
internal.rs1use comrak::nodes::ValidationError;
4
5use super::{DocumentError, Feature};
6
7#[derive(Debug, thiserror::Error)]
9pub enum InternalError {
10 #[error("Markdown splice range is outside the source")]
12 MarkdownSpliceOutOfBounds,
13 #[error("Markdown tree has a {child} node inside a {parent} node")]
15 MarkdownTreeInvalid {
16 parent: &'static str,
18 child: &'static str,
20 },
21 #[error("value needs {feature}, which validation did not reject")]
24 FeatureNotValidated {
25 feature: Feature,
27 },
28 #[error("rendered TOML is invalid")]
30 TomlRenderedInvalid {
31 #[source]
33 source: Box<toml_edit::TomlError>,
34 },
35 #[error("rendered YAML is invalid")]
37 YamlRenderedInvalid {
38 #[source]
40 source: Box<DocumentError>,
41 },
42 #[error("YAML node is missing from the parsed document")]
44 YamlNodeMissing,
45 #[error("YAML node span {start}..{end} is outside the source")]
47 YamlSpanInvalid {
48 start: usize,
50 end: usize,
52 },
53}
54
55impl InternalError {
56 pub(crate) fn markdown_tree(error: &ValidationError<'_>) -> Self {
57 match error {
58 ValidationError::InvalidChildType { parent, child } => Self::MarkdownTreeInvalid {
59 parent: parent.data().value.xml_node_name(),
60 child: child.data().value.xml_node_name(),
61 },
62 }
63 }
64
65 pub(crate) fn toml_rendered(source: toml_edit::TomlError) -> Self {
66 Self::TomlRenderedInvalid {
67 source: Box::new(source),
68 }
69 }
70
71 pub(crate) fn yaml_rendered(source: DocumentError) -> Self {
72 Self::YamlRenderedInvalid {
73 source: Box::new(source),
74 }
75 }
76}