Removed new type error

This commit is contained in:
jaby 2022-11-27 22:19:43 +01:00
parent 0d3686b7d0
commit eef5082c93
2 changed files with 4 additions and 30 deletions

View File

@ -1,4 +1,4 @@
use super::{Error, ErrorString};
use super::Error;
use std::path::PathBuf;
mod xml;

View File

@ -2,11 +2,11 @@ use std::path::PathBuf;
use tool_helper::format_if_error;
use crate::config_reader::Directory;
use super::{Configuration, ErrorString, File};
use super::{Configuration, Error, File};
pub fn parse(xml: String) -> Result<Configuration, Error> {
let mut config = Configuration::new();
let parser = roxmltree::Document::parse(xml.as_str())?;
let parser = format_if_error!(roxmltree::Document::parse(xml.as_str()), "Parsing XML file failed with: {error_text}")?;
let children = parser.root().children();
for node in children {
@ -94,7 +94,7 @@ fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Resul
"true" | "1" => Ok(true),
"false" | "0" => Ok(false),
_ => {
return Err(Error::Generic(super::Error::from_text(format!("Attribute \"{}\" expects either true,false or 1,0 as valid attributes - found {}", attribute_name, bool_str))));
return Err(Error::from_text(format!("Attribute \"{}\" expects either true,false or 1,0 as valid attributes - found {}", attribute_name, bool_str)));
}
}
}
@ -102,30 +102,4 @@ fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Resul
else {
Ok(false)
}
}
pub enum Error {
XML(roxmltree::Error),
Generic(super::Error)
}
impl ErrorString for Error {
fn to_string(self) -> String {
match self {
Self::XML(xml) => xml.to_string(),
Self::Generic(generic) => generic.to_string()
}
}
}
impl std::convert::From<roxmltree::Error> for Error {
fn from(error: roxmltree::Error) -> Error {
Error::XML(error)
}
}
impl std::convert::From<super::Error> for Error {
fn from(error: super::Error) -> Error {
Error::Generic(error)
}
}