Skip to content

Commit 6d55e50

Browse files
authored
Merge pull request #182 from afgTheCat/main
fix: prevent last position underflow
2 parents d2d6dc6 + d8862da commit 6d55e50

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/app/business_logic/collection.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ impl App<'_> {
4343
let file_format = self.config.get_preferred_collection_file_format();
4444

4545
let collections_len = self.collections.len();
46+
let last_position = match collections_len == 0 {
47+
true => None,
48+
false => Some(collections_len - 1),
49+
};
50+
4651
let new_collection = Collection {
4752
name: new_collection_name.clone(),
48-
last_position: Some(collections_len - 1),
53+
last_position,
4954
requests: vec![],
5055
path: ARGS.directory.as_ref().unwrap().join(format!("{}.{}", new_collection_name, file_format.to_string())),
5156
file_format,
@@ -166,4 +171,4 @@ impl App<'_> {
166171
self.save_collection_to_file(index);
167172
}
168173
}
169-
}
174+
}

0 commit comments

Comments
 (0)