Improved error handling

This commit is contained in:
Jaby
2022-11-04 11:32:55 +01:00
committed by Jaby
parent 22d5fefd11
commit a2858e0daf
6 changed files with 42 additions and 4 deletions

View File

@@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
cdtypes = {path = "../cdtypes"}
paste = "*"
roxmltree = "*"
tool_helper = {path = "../tool_helper"}

View File

@@ -1,5 +1,6 @@
use super::{Error, ErrorString};
mod xml;
pub fn parse_xml(xml: String) {
println!("Wuff: {}", xml);
pub fn parse_xml(xml: String) -> Result<(), Error> {
Ok(xml::parse(xml)?)
}

View File

@@ -0,0 +1,21 @@
use super::ErrorString;
pub fn parse(xml: String) -> Result<(), Error> {
roxmltree::Document::parse(xml.as_str())?;
Ok(())
}
pub struct Error(roxmltree::Error);
impl ErrorString for Error {
fn to_string(self) -> String {
self.0.to_string()
}
}
impl std::convert::From<roxmltree::Error> for Error {
fn from(error: roxmltree::Error) -> Error {
Error(error)
}
}

View File

@@ -1,3 +1,5 @@
pub use tool_helper::{Error, ErrorString};
pub mod config_reader;
pub mod encoder;
pub mod file_writer;

View File

@@ -59,8 +59,7 @@ fn run_main() -> Result<(), Error> {
}
fn run_main_xml() -> Result<(), Error> {
config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?);
Ok(())
config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)
}
fn main() {