Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e205672

Browse files
committedMar 29, 2025·
Avoid panic when duplicate found.
1 parent d9bf16e commit e205672

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed
 

‎src/core/sequence/rename.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,26 @@ impl<'a> SequenceRenaming<'a> {
228228
names.iter().for_each(|(origin, destination)| {
229229
let values = matrix.shift_remove(origin);
230230
if let Some(value) = values {
231+
// We check the sequence length if the ID is not unique
232+
if matrix.contains_key(destination) {
233+
log::warn!(
234+
"ID {} already exists. \
235+
Keeping the longest sequences.",
236+
destination
237+
);
238+
let new_value = matrix.get(destination).expect("Failed getting value");
239+
if new_value.len() > value.len() {
240+
matrix.insert(origin.to_string(), value);
241+
return;
242+
}
243+
}
231244
matrix.insert(destination.to_string(), value);
232245
}
233246
});
234-
235-
assert_eq!(
236-
original_size,
237-
matrix.len(),
238-
"Failed renaming files. New ID counts does not match original ID counts. \
239-
Original ID counts: {}. New ID counts: {}",
240-
original_size,
247+
log::warn!(
248+
"Duplicate IDs found! Original ID count: {}. \
249+
New ID count: {}",
250+
original_size - matrix.len(),
241251
matrix.len()
242252
);
243253
(matrix, header)

0 commit comments

Comments
 (0)
Please sign in to comment.