From 86c96398b7615fbe9e8def943b15f1447aead260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81my=20Rakic?= Date: Sun, 22 Sep 2019 02:04:35 +0200 Subject: [PATCH] Print an error when trying to load a fact file that is missing --- src/tab_delim.rs | 49 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/tab_delim.rs b/src/tab_delim.rs index 609ab19fcb0..93218c74f54 100644 --- a/src/tab_delim.rs +++ b/src/tab_delim.rs @@ -57,31 +57,40 @@ fn load_tab_delimited_file(tables: &mut InternerTables, path: &Path) -> io: where Row: for<'input> FromTabDelimited<'input>, { - let file = File::open(path)?; + match File::open(path) { + Ok(file) => io::BufReader::new(file) + .lines() + .enumerate() + .map(|(index, line)| { + let line = line?; + let mut columns = line.split('\t'); + let row = match FromTabDelimited::parse(tables, &mut columns) { + None => { + error!("error parsing line {} of `{}`", index + 1, path.display()); + process::exit(1); + } - io::BufReader::new(file) - .lines() - .enumerate() - .map(|(index, line)| { - let line = line?; - let mut columns = line.split('\t'); - let row = match FromTabDelimited::parse(tables, &mut columns) { - None => { - error!("error parsing line {} of `{}`", index + 1, path.display()); + Some(v) => v, + }; + + if columns.next().is_some() { + error!("extra data on line {} of `{}`", index + 1, path.display()); process::exit(1); } - Some(v) => v, - }; - - if columns.next().is_some() { - error!("extra data on line {} of `{}`", index + 1, path.display()); - process::exit(1); - } + Ok(row) + }) + .collect(), - Ok(row) - }) - .collect() + Err(e) => { + error!( + "Error opening file '{}': {}. Defaulting to empty relation", + path.display(), + e + ); + Ok(Vec::new()) + } + } } impl<'input, T> FromTabDelimited<'input> for T