Skip to content

Commit 5cda5c7

Browse files
authored
Merge pull request #477 from jqnatividad/bump-to-quick-xml-0.37
Bump to quick-xml 0.37
2 parents 5cd2e2c + 5ddf2bd commit 5cda5c7

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ encoding_rs = "0.8"
2121
fast-float2 = "0.2"
2222
log = "0.4"
2323
serde = "1.0"
24-
quick-xml = { version = "0.36", features = ["encoding"] }
24+
quick-xml = { version = "0.37", features = ["encoding"] }
2525
zip = { version = "2", default-features = false, features = ["deflate"] }
2626
chrono = { version = "0.4", features = [
2727
"serde",

src/ods.rs

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ pub enum OdsError {
6060
Password,
6161
/// Worksheet not found
6262
WorksheetNotFound(String),
63+
64+
/// XML attribute error
65+
AttrError(quick_xml::events::attributes::AttrError),
66+
/// XML encoding error
67+
EncodingError(quick_xml::encoding::EncodingError),
6368
}
6469

6570
/// Ods reader options
@@ -74,6 +79,8 @@ from_err!(zip::result::ZipError, OdsError, Zip);
7479
from_err!(quick_xml::Error, OdsError, Xml);
7580
from_err!(std::string::ParseError, OdsError, Parse);
7681
from_err!(std::num::ParseFloatError, OdsError, ParseFloat);
82+
from_err!(quick_xml::events::attributes::AttrError, OdsError, Xml);
83+
from_err!(quick_xml::encoding::EncodingError, OdsError, Xml);
7784

7885
impl std::fmt::Display for OdsError {
7986
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -94,6 +101,8 @@ impl std::fmt::Display for OdsError {
94101
}
95102
OdsError::Password => write!(f, "Workbook is password protected"),
96103
OdsError::WorksheetNotFound(name) => write!(f, "Worksheet '{name}' not found"),
104+
OdsError::AttrError(e) => write!(f, "XML attribute Error: {e}"),
105+
OdsError::EncodingError(e) => write!(f, "XML encoding Error: {e}"),
97106
}
98107
}
99108
}
@@ -107,6 +116,8 @@ impl std::error::Error for OdsError {
107116
OdsError::Parse(e) => Some(e),
108117
OdsError::ParseInt(e) => Some(e),
109118
OdsError::ParseFloat(e) => Some(e),
119+
OdsError::AttrError(e) => Some(e),
120+
OdsError::EncodingError(e) => Some(e),
110121
_ => None,
111122
}
112123
}

src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ macro_rules! from_err {
44
($from:ty, $to:tt, $var:tt) => {
55
impl From<$from> for $to {
66
fn from(e: $from) -> $to {
7-
$to::$var(e)
7+
$to::$var(e.into())
88
}
99
}
1010
};

src/xlsb/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ pub enum XlsbError {
8080
Password,
8181
/// Worksheet not found
8282
WorksheetNotFound(String),
83+
/// XML Encoding error
84+
Encoding(quick_xml::encoding::EncodingError),
8385
}
8486

8587
from_err!(std::io::Error, XlsbError, Io);
8688
from_err!(zip::result::ZipError, XlsbError, Zip);
8789
from_err!(quick_xml::Error, XlsbError, Xml);
90+
from_err!(quick_xml::encoding::EncodingError, XlsbError, Encoding);
8891

8992
impl std::fmt::Display for XlsbError {
9093
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -114,6 +117,7 @@ impl std::fmt::Display for XlsbError {
114117
}
115118
XlsbError::Password => write!(f, "Workbook is password protected"),
116119
XlsbError::WorksheetNotFound(name) => write!(f, "Worksheet '{name}' not found"),
120+
XlsbError::Encoding(e) => write!(f, "XML encoding error: {e}"),
117121
}
118122
}
119123
}
@@ -183,7 +187,12 @@ impl<RS: Read + Seek> Xlsb<RS> {
183187
key: QName(b"Target"),
184188
value: v,
185189
} => {
186-
target = Some(xml.decoder().decode(&v)?.into_owned());
190+
target = Some(
191+
xml.decoder()
192+
.decode(&v)
193+
.map_err(XlsbError::Encoding)?
194+
.into_owned(),
195+
);
187196
}
188197
_ => (),
189198
}

src/xlsx/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub enum XlsxError {
8989
TableNotFound(String),
9090
/// The specified sheet is not a worksheet
9191
NotAWorksheet(String),
92+
/// XML Encoding error
93+
Encoding(quick_xml::encoding::EncodingError),
94+
/// XML attribute error
95+
XmlAttribute(quick_xml::events::attributes::AttrError),
9296
}
9397

9498
from_err!(std::io::Error, XlsxError, Io);
@@ -98,6 +102,12 @@ from_err!(quick_xml::Error, XlsxError, Xml);
98102
from_err!(std::string::ParseError, XlsxError, Parse);
99103
from_err!(std::num::ParseFloatError, XlsxError, ParseFloat);
100104
from_err!(std::num::ParseIntError, XlsxError, ParseInt);
105+
from_err!(quick_xml::encoding::EncodingError, XlsxError, Encoding);
106+
from_err!(
107+
quick_xml::events::attributes::AttrError,
108+
XlsxError,
109+
XmlAttribute
110+
);
101111

102112
impl std::fmt::Display for XlsxError {
103113
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -139,6 +149,8 @@ impl std::fmt::Display for XlsxError {
139149
XlsxError::Password => write!(f, "Workbook is password protected"),
140150
XlsxError::TableNotFound(n) => write!(f, "Table '{n}' not found"),
141151
XlsxError::NotAWorksheet(typ) => write!(f, "Expecting a worksheet, got {typ}"),
152+
XlsxError::Encoding(e) => write!(f, "XML encoding error: {e}"),
153+
XlsxError::XmlAttribute(e) => write!(f, "XML attribute error: {e}"),
142154
}
143155
}
144156
}
@@ -153,6 +165,8 @@ impl std::error::Error for XlsxError {
153165
XlsxError::Parse(e) => Some(e),
154166
XlsxError::ParseInt(e) => Some(e),
155167
XlsxError::ParseFloat(e) => Some(e),
168+
XlsxError::Encoding(e) => Some(e),
169+
XlsxError::XmlAttribute(e) => Some(e),
156170
_ => None,
157171
}
158172
}

0 commit comments

Comments
 (0)