diff --git a/noodles-sam/CHANGELOG.md b/noodles-sam/CHANGELOG.md index b1b406905..1a9173af6 100644 --- a/noodles-sam/CHANGELOG.md +++ b/noodles-sam/CHANGELOG.md @@ -8,6 +8,10 @@ This can be used to read the raw SAM header. +### Changed + + * sam/header/parser: Keep existing record in header on a duplicate ID error. + ## 0.67.0 - 2024-12-12 ### Changed diff --git a/noodles-sam/src/header/parser.rs b/noodles-sam/src/header/parser.rs index 97a625758..57b0c3de0 100644 --- a/noodles-sam/src/header/parser.rs +++ b/noodles-sam/src/header/parser.rs @@ -170,7 +170,7 @@ fn extract_version(src: &[u8]) -> Option { fn try_insert(map: &mut IndexMap, key: K, value: V, f: F) -> Result<(), E> where - K: Hash + Eq, + K: Hash + Eq + Clone, F: FnOnce(K) -> E, { use indexmap::map::Entry; @@ -180,10 +180,7 @@ where e.insert(value); Ok(()) } - Entry::Occupied(e) => { - let (k, _) = e.swap_remove_entry(); - Err(f(k)) - } + Entry::Occupied(e) => Err(f(e.key().clone())), } }