1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum SchemaError {
8 DuplicateType(String),
10 UnknownTopNode(String),
12 UnknownContentRef {
14 in_type: String,
16 reference: String,
18 },
19 BadContentExpression {
21 in_type: String,
23 message: String,
25 },
26 Empty,
28}
29
30impl fmt::Display for SchemaError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 SchemaError::DuplicateType(n) => write!(f, "duplicate type name `{n}`"),
34 SchemaError::UnknownTopNode(n) => {
35 write!(f, "top node `{n}` is not a declared node type")
36 }
37 SchemaError::UnknownContentRef { in_type, reference } => {
38 write!(f, "content of `{in_type}` references unknown `{reference}`")
39 }
40 SchemaError::BadContentExpression { in_type, message } => {
41 write!(f, "content expression of `{in_type}` is invalid: {message}")
42 }
43 SchemaError::Empty => write!(f, "schema declares no node types"),
44 }
45 }
46}
47
48impl std::error::Error for SchemaError {}
49
50#[derive(Debug, Clone, PartialEq, Eq)]
52pub enum DocError {
53 UnknownNodeType(String),
55 UnknownMarkType(String),
57 InvalidContent {
59 parent: String,
61 },
62 PositionOutOfRange {
64 pos: usize,
66 max: usize,
68 },
69 MalformedJson(String),
71 HtmlParse(String),
74}
75
76impl fmt::Display for DocError {
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 match self {
79 DocError::UnknownNodeType(n) => write!(f, "unknown node type `{n}`"),
80 DocError::UnknownMarkType(n) => write!(f, "unknown mark type `{n}`"),
81 DocError::InvalidContent { parent } => {
82 write!(f, "content does not match the schema for `{parent}`")
83 }
84 DocError::PositionOutOfRange { pos, max } => {
85 write!(f, "position {pos} out of range (max {max})")
86 }
87 DocError::MalformedJson(m) => write!(f, "malformed document JSON: {m}"),
88 DocError::HtmlParse(m) => write!(f, "could not parse HTML: {m}"),
89 }
90 }
91}
92
93impl std::error::Error for DocError {}