Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clap usable, add warnings on missing fact files #129

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions src/tab_delim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,40 @@ fn load_tab_delimited_file<Row>(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
Expand Down