Skip to content

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
@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?

@nh13 nh13 merged commit a004152 into main Feb 12, 2025
@nh13 nh13 deleted the jf/validate-header branch February 12, 2025 23:56
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.

4 participants