Skip to main content

ephemeris_documents/error/
markdown.rs

1//! Errors from Markdown documents and selectors.
2
3use std::fmt;
4
5/// Error returned while validating, rendering, or reconciling Markdown.
6#[derive(Debug, thiserror::Error)]
7pub enum MarkdownError {
8    /// A heading level is outside `1..=6`.
9    #[error("heading level {level} is outside 1..=6")]
10    HeadingLevelOutOfRange {
11        /// The out-of-range heading level.
12        level: u8,
13    },
14    /// A heading selector's replacement content spans multiple lines.
15    #[error("heading selector content spans more than one line")]
16    HeadingContentMultiline,
17    /// A code block's language spans multiple lines.
18    #[error("code block language spans more than one line")]
19    CodeBlockLanguageMultiline,
20    /// A marker name is empty or has leading or trailing whitespace.
21    #[error("marker name is empty or has surrounding whitespace")]
22    MarkerNameInvalid,
23    /// Partial Markdown ownership was requested with no current document.
24    #[error("partial Markdown ownership requires an existing document")]
25    DocumentMissing,
26    /// A heading selector matched no heading in the current document.
27    #[error("document has no heading of level {level}")]
28    HeadingNotFound {
29        /// The selector's heading level.
30        level: u8,
31    },
32    /// A heading selector matched more than one heading.
33    #[error("document has more than one heading of level {level}")]
34    HeadingAmbiguous {
35        /// The selector's heading level.
36        level: u8,
37    },
38    /// A marker's blocks render a heading at a level that a heading selector
39    /// matches.
40    #[error("marker `{name}` renders a level {level} heading that a heading selector matches")]
41    HeadingInsideMarker {
42        /// The heading level shared with a heading selector.
43        level: u8,
44        /// The marker's name.
45        name: String,
46    },
47    /// A named marker was not found in the current document.
48    #[error("document has no marker `{marker}`")]
49    MarkerNotFound {
50        /// The marker name that was not found.
51        marker: String,
52    },
53    /// A begin marker uses a name that an earlier, closed region already
54    /// has.
55    #[error("marker `{marker}` is used more than once")]
56    MarkerDuplicated {
57        /// The repeated marker name.
58        marker: String,
59    },
60    /// A begin marker was opened while another region was still open.
61    #[error("marker `{marker}` begins inside another marker region")]
62    MarkerNested {
63        /// The name of the inner begin marker.
64        marker: String,
65    },
66    /// A begin marker has no matching end marker.
67    #[error("begin marker `{marker}` has no matching end marker")]
68    MarkerBeginUnmatched {
69        /// The begin marker name with no matching end marker.
70        marker: String,
71    },
72    /// An end marker has no matching begin marker.
73    #[error("end marker `{marker}` has no matching begin marker")]
74    MarkerEndUnmatched {
75        /// The end marker name with no matching begin marker.
76        marker: String,
77    },
78    /// A marker comment could not be parsed as a begin or end marker.
79    #[error("marker comment on line {line} is malformed")]
80    MarkerMalformed {
81        /// The 1 based line number of the marker comment.
82        line: usize,
83    },
84    /// Two or more selectors target overlapping ranges.
85    #[error("selectors overlap")]
86    SelectorsOverlapping,
87    /// Comrak failed to render the Markdown AST to text.
88    #[error("Markdown rendering failed")]
89    RenderFailed {
90        /// The underlying render failure.
91        #[source]
92        source: fmt::Error,
93    },
94}