Skip to main content

ephemeris_documents/error/
annotation.rs

1//! Errors from decoding annotation markers.
2
3use std::fmt;
4
5use facet_value::ValueError as FacetValueError;
6
7/// Error returned while decoding inline annotation markers.
8#[derive(Debug, thiserror::Error)]
9pub enum AnnotationError {
10    /// An annotation marker does not have the expected shape.
11    #[error("annotation marker is malformed")]
12    Marker {
13        /// The underlying decoding failure.
14        #[source]
15        source: Box<FacetValueError>,
16    },
17    /// An annotation marker has no `value` field.
18    #[error("annotation marker has no `value` field")]
19    MissingValue,
20    /// An annotation field was set more than once by composed wrappers.
21    #[error("annotation sets field `{field}` more than once")]
22    FieldSetTwice {
23        /// The field that was set twice.
24        field: MarkerField,
25    },
26    /// An annotation requests a string style for a value that is not a string.
27    #[error("annotation requests a string style for a value that is not a string")]
28    StyleOnNonString,
29    /// An annotation sets `order` on a value that is not an object entry.
30    #[error("annotation sets `order` on a value that is not an object entry")]
31    OrderOutsideObject,
32    /// An annotation requests a dotted table for a value that is not an object.
33    #[error("annotation requests a dotted table for a value that is not an object")]
34    DottedOnNonObject,
35}
36
37/// A field of an annotation marker.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum MarkerField {
40    /// The `order` field.
41    Order,
42    /// The `string` field.
43    String,
44    /// The `comment` field.
45    Comment,
46    /// The `dotted` field.
47    Dotted,
48}
49
50impl fmt::Display for MarkerField {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        f.write_str(match self {
53            Self::Order => "order",
54            Self::String => "string",
55            Self::Comment => "comment",
56            Self::Dotted => "dotted",
57        })
58    }
59}