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

Validate DelimFile headers #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Validate DelimFile headers #17

wants to merge 3 commits into from

Conversation

theJasonFan
Copy link
Member

@theJasonFan theJasonFan commented Apr 24, 2024

Adds validation to parse DelimFile headers.

@@ -24,6 +24,7 @@ flate2 = "^1"
# For auto-serialization of structs to csv/tsv
csv = "^1"
serde = { version = "^1.0.123", features = ["derive"] }
serde-aux = "^4"
Copy link
Member Author

@theJasonFan theJasonFan Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used for serde / field name introspection. fqtk uses the same crate.

@@ -171,8 +171,16 @@ impl<D: DeserializeOwned> DelimFileReader<D> {
.has_headers(true)
.quoting(quote)
.from_reader(reader);
assert!(csv_reader.has_headers(), "Expected input file to have a header row");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this assert. It wasn't actually checking for a header line but instead just checks that the reader is configured to read a header.

let header = csv_reader.headers().map_err(FgError::ConversionError)?.to_owned();
if !header.is_empty() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty files return empty headers, so we validate headers for only non-empty TSVs.

@theJasonFan theJasonFan requested review from nh13, jdidion, ameynert and tfenne and removed request for nh13 April 24, 2024 21:50
src/io/mod.rs Outdated Show resolved Hide resolved
src/io/mod.rs Outdated Show resolved Hide resolved
@theJasonFan theJasonFan marked this pull request as ready for review April 25, 2024 15:10
@ameynert
Copy link

I think we still get a bad deserialization error for a degenerate TSV with an empty header but non-empty body with an incorrect delimiter.

If this is still the case, could you add a test for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants