1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
7pub enum CoreError {
8 #[error("I/O error on {path}: {source}")]
10 Io {
11 path: PathBuf,
13 #[source]
15 source: std::io::Error,
16 },
17
18 #[error("not a valid ZIP/OPC package: {0}")]
20 Zip(String),
21
22 #[error("XML parse error in {part}: {message}")]
24 Xml {
25 part: String,
27 message: String,
29 },
30
31 #[error("missing package part: {0}")]
33 MissingPart(String),
34
35 #[error("XML path not found: {0}")]
37 Path(String),
38
39 #[error("XML formula error: {0}")]
41 Formula(String),
42
43 #[error("XML patch error: {0}")]
45 Patch(String),
46
47 #[error("XML update error: {0}")]
49 Update(String),
50
51 #[error("{0}")]
53 Invalid(String),
54}
55
56impl CoreError {
57 pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
59 CoreError::Io {
60 path: path.into(),
61 source,
62 }
63 }
64
65 pub fn xml(part: impl Into<String>, message: impl Into<String>) -> Self {
67 CoreError::Xml {
68 part: part.into(),
69 message: message.into(),
70 }
71 }
72
73 pub fn invalid(msg: impl Into<String>) -> Self {
75 CoreError::Invalid(msg.into())
76 }
77
78 pub fn formula(msg: impl Into<String>) -> Self {
80 CoreError::Formula(msg.into())
81 }
82
83 pub fn patch(msg: impl Into<String>) -> Self {
85 CoreError::Patch(msg.into())
86 }
87
88 pub fn update(msg: impl Into<String>) -> Self {
90 CoreError::Update(msg.into())
91 }
92}
93
94impl From<String> for CoreError {
95 fn from(msg: String) -> Self {
96 CoreError::Invalid(msg)
97 }
98}