opys_engine/mdprism/
error.rs1#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5#[error("schema:{line}:{col}: {message}")]
6pub struct SchemaError {
7 pub line: usize,
8 pub col: usize,
9 pub message: String,
10}
11
12impl SchemaError {
13 pub(crate) fn new(line: usize, col: usize, message: impl Into<String>) -> Self {
14 SchemaError {
15 line,
16 col,
17 message: message.into(),
18 }
19 }
20}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct Problem {
26 pub path: Vec<String>,
27 pub message: String,
28}
29
30impl std::fmt::Display for Problem {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 if self.path.is_empty() {
33 write!(f, "{}", self.message)
34 } else {
35 write!(f, "{}: {}", self.path.join(" › "), self.message)
36 }
37 }
38}
39
40#[derive(Debug, Clone, thiserror::Error)]
42pub enum RenderError {
43 #[error("required field '{0}' is missing from the data")]
44 MissingField(String),
45 #[error("field '{field}' has wrong type: expected {expected}")]
46 WrongType {
47 field: String,
48 expected: &'static str,
49 },
50}
51
52#[derive(Debug, Clone, thiserror::Error)]
54pub enum EditError {
55 #[error("target path does not resolve to an editable node")]
56 TargetNotFound,
57 #[error("index {index} is out of range (list has {len} items)")]
58 IndexOutOfRange { index: usize, len: usize },
59}