1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, FopError>;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct Location {
11 pub line: usize,
12 pub column: usize,
13}
14
15impl Location {
16 pub fn new(line: usize, column: usize) -> Self {
17 Self { line, column }
18 }
19
20 pub fn unknown() -> Self {
21 Self { line: 0, column: 0 }
22 }
23}
24
25impl std::fmt::Display for Location {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 if self.line == 0 && self.column == 0 {
28 write!(f, "unknown location")
29 } else {
30 write!(f, "line {}, column {}", self.line, self.column)
31 }
32 }
33}
34
35#[derive(Error, Debug)]
37pub enum FopError {
38 #[error("XML parsing error at {location}: {message}")]
40 XmlErrorWithLocation {
41 message: String,
42 location: Location,
43 suggestion: Option<String>,
44 },
45
46 #[error("XML parsing error: {0}")]
48 XmlError(String),
49
50 #[error("Entity resolution error at {location}: {message}")]
52 EntityError { message: String, location: Location },
53
54 #[error("Invalid property value for {property}: {value}")]
56 InvalidPropertyValue { property: String, value: String },
57
58 #[error("Unknown property: {0}")]
60 UnknownProperty(String),
61
62 #[error("Invalid element: {0}")]
64 InvalidElement(String),
65
66 #[error("Invalid element nesting: {child} cannot be a child of {parent}")]
68 InvalidNesting { parent: String, child: String },
69
70 #[error("Missing required attribute {attribute} on element {element}")]
72 MissingAttribute { element: String, attribute: String },
73
74 #[error("Property validation error for {property}: {value} - {reason}")]
76 PropertyValidation {
77 property: String,
78 value: String,
79 reason: String,
80 },
81
82 #[error("I/O error: {0}")]
84 IoError(#[from] std::io::Error),
85
86 #[error("Parse error: {0}")]
88 ParseError(String),
89
90 #[error("{0}")]
92 Generic(String),
93}