Move validation after parsing
This allows quickxml parsing errors to be reported before validation.
@@ -68,7 +68,6 @@ impl TradeItem {
}
pub fn get_trade_items_from_xml(path: &str) -> Result<Vec<TradeItem>, ProductGdsnError> {
- validate_product_definitons(path)?;
let mut xml_file = std::fs::File::open(path).map_err(|error| {
ProductGdsnError::InvalidArgument(InvalidArgumentError::new(
path.to_string(),
@@ -91,6 +90,8 @@ pub fn get_trade_items_from_xml(path: &str) -> Result<Vec<TradeItem>, ProductGds
))
})?;
+ validate_product_definitons(path)?;
+
let mut reader = Reader::from_str(&xml_str);
reader.trim_text(true);
let mut buf = Vec::new();
