Refactor: File::from_parser_result() shouldnt do error handling, do this in calling code
This commit is contained in:
parent
b6af948c0e
commit
1b1f0678cb
2 changed files with 13 additions and 10 deletions
|
@ -128,7 +128,14 @@ impl StorageBackend {
|
||||||
if let Ok(file) = FSFile::open(path) {
|
if let Ok(file) = FSFile::open(path) {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
file.read_to_string(&mut s);
|
file.read_to_string(&mut s);
|
||||||
File::from_parser_result(id, p.read(s))
|
let parser_out = p.read(s);
|
||||||
|
if let Ok((header, data)) = parser_out {
|
||||||
|
Some(File::from_parser_result(id, header, data))
|
||||||
|
} else {
|
||||||
|
info!("Cannot build File from ID '{}'. Parser Error:\n{}",
|
||||||
|
id, parser_out.err().unwrap());
|
||||||
|
None
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,15 +185,11 @@ impl File {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_parser_result(id: FileID, r: Result<(FileHeaderData, String), ParserError>) -> Option<File> {
|
pub fn from_parser_result(id: FileID, header: FileHeaderData, data: String) -> File {
|
||||||
if let Ok((header, data)) = r {
|
File {
|
||||||
Some(File {
|
|
||||||
header: header,
|
header: header,
|
||||||
data: data,
|
data: data,
|
||||||
id: id,
|
id: id,
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue