Skip to content

Commit

Permalink
Improve file reading error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Oct 12, 2023
1 parent da9a185 commit f748f00
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rust/agama-migrate-wicked/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ pub fn read_xml(str: &str) -> Result<Vec<Interface>, quick_xml::DeError> {
from_str(replace_colons(str).as_str())
}

pub fn read_xml_file(path: PathBuf) -> Result<Vec<Interface>, quick_xml::DeError> {
let contents = fs::read_to_string(path).expect("Should have been able to read the file");
read_xml(contents.as_str())
pub fn read_xml_file(path: PathBuf) -> Result<Vec<Interface>, anyhow::Error> {
let contents = match fs::read_to_string(path.clone()) {
Ok(contents) => contents,
Err(e) => {
return Err(anyhow::anyhow!(
"Couldn't read {}: {}",
path.as_path().display(),
e
))
}
};
Ok(read_xml(contents.as_str())?)
}

fn replace_colons(colon_string: &str) -> String {
Expand Down

0 comments on commit f748f00

Please sign in to comment.