Skip to content

Commit

Permalink
vcf/header/parser: Keep existing record in header on a duplicate ID e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
zaeleus committed Dec 20, 2024
1 parent a14bb31 commit 4b6ee3d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 66 deletions.
4 changes: 4 additions & 0 deletions noodles-vcf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

This can be used to read the raw VCF header.

### Changed

* vcf/header/parser: Keep existing record in header on a duplicate ID error.

## 0.69.0 - 2024-12-12

### Changed
Expand Down
25 changes: 5 additions & 20 deletions noodles-vcf/src/header/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ fn try_insert_info(
.map(|(k, v)| self::Entry::Info(k, v))
.unwrap())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(ParseError::DuplicateInfoId(id))
}
Entry::Occupied(entry) => Err(ParseError::DuplicateInfoId(entry.key().into())),
}
}

Expand All @@ -262,10 +259,7 @@ fn try_insert_filter(
.map(|(k, v)| self::Entry::Filter(k, v))
.unwrap())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(ParseError::DuplicateFilterId(id))
}
Entry::Occupied(entry) => Err(ParseError::DuplicateFilterId(entry.key().into())),
}
}

Expand All @@ -288,10 +282,7 @@ fn try_insert_format(
.map(|(k, v)| self::Entry::Format(k, v))
.unwrap())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(ParseError::DuplicateFormatId(id))
}
Entry::Occupied(entry) => Err(ParseError::DuplicateFormatId(entry.key().into())),
}
}

Expand All @@ -314,10 +305,7 @@ fn try_insert_alternative_allele(
.map(|(k, v)| self::Entry::AlternativeAllele(k, v))
.unwrap())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(ParseError::DuplicateAlternativeAlleleId(id))
}
Entry::Occupied(entry) => Err(ParseError::DuplicateAlternativeAlleleId(entry.key().into())),
}
}

Expand All @@ -340,10 +328,7 @@ fn try_insert_contig(
.map(|(k, v)| self::Entry::Contig(k, v))
.unwrap())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(ParseError::DuplicateContigId(id))
}
Entry::Occupied(entry) => Err(ParseError::DuplicateContigId(entry.key().into())),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
11 changes: 4 additions & 7 deletions noodles-vcf/src/header/parser/record/value/map/contig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
11 changes: 4 additions & 7 deletions noodles-vcf/src/header/parser/record/value/map/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
11 changes: 4 additions & 7 deletions noodles-vcf/src/header/parser/record/value/map/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
11 changes: 4 additions & 7 deletions noodles-vcf/src/header/parser/record/value/map/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
11 changes: 4 additions & 7 deletions noodles-vcf/src/header/parser/record/value/map/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,10 @@ fn try_insert(
entry.insert(value);
Ok(())
}
Entry::Occupied(entry) => {
let (t, _) = entry.swap_remove_entry();
Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(t)),
))
}
Entry::Occupied(entry) => Err(ParseError::new(
id.clone(),
ParseErrorKind::DuplicateTag(Tag::Other(entry.key().clone())),
)),
}
}

Expand Down
5 changes: 1 addition & 4 deletions noodles-vcf/src/header/record/value/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ fn try_insert(
entry.insert(m);
Ok(())
}
Entry::Occupied(entry) => {
let (id, _) = entry.swap_remove_entry();
Err(AddError::DuplicateId(id))
}
Entry::Occupied(entry) => Err(AddError::DuplicateId(entry.key().into())),
}
}

Expand Down

0 comments on commit 4b6ee3d

Please sign in to comment.