Fix Bug where series existing in history but not in config crashed the bot
All checks were successful
Run Tests on Code / run-tests (push) Successful in 32s

This commit is contained in:
Neshura 2023-12-20 20:46:21 +01:00
parent 2531af3739
commit c85f761e85
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -40,20 +40,25 @@ async fn print_info(arc_data: &Arc<RwLock<SharedData>>, min_len_series: &mut u32
println!("{:#<1$}", "", separator_width); println!("{:#<1$}", "", separator_width);
let mut sorted_series: Vec<(&String, &PostHistory)> = data.post_history.series.iter().collect(); let mut sorted_series: Vec<(&String, &PostHistory)> = data.post_history.series.iter().collect();
sorted_series.sort_by(|(a, _), (b, _)| a.cmp(b)); sorted_series.sort_by(|(a, _), (b, _)| a.cmp(b));
sorted_series.iter().for_each(|(series, post_history)| { for (series, post_history) in sorted_series.iter() {
if series.len() > local_min_len_series { if series.len() > local_min_len_series {
local_min_len_series = series.len() + 1; local_min_len_series = series.len() + 1;
*min_len_series = local_min_len_series as u32; *min_len_series = local_min_len_series as u32;
} }
let series_config = data.config.series let series_config = match data.config.series
.iter() .iter()
.find(|ser| {&&ser.slug == series}) .find(|ser| {
.expect("Config should not parse without this"); &&ser.slug == series
}) {
Some(data) => data,
None => continue,
};
let mut sorted_parts: Vec<(&String, &PostHistoryInner)> = post_history.parts.iter().collect(); let mut sorted_parts: Vec<(&String, &PostHistoryInner)> = post_history.parts.iter().collect();
sorted_parts.sort_by(|(a, _), (b, _)| a.cmp(b)); sorted_parts.sort_by(|(a, _), (b, _)| a.cmp(b));
sorted_parts.iter().for_each(|(part, part_history)| { for (part, part_history) in sorted_parts.iter() {
if part_history.volume.len() > local_min_len_slug { if part_history.volume.len() > local_min_len_slug {
local_min_len_slug = part_history.chapter.len() + 1; local_min_len_slug = part_history.chapter.len() + 1;
@ -82,8 +87,8 @@ async fn print_info(arc_data: &Arc<RwLock<SharedData>>, min_len_series: &mut u32
print!("{:<1$}| ", "", local_min_len_slug - part_history.chapter.len()); print!("{:<1$}| ", "", local_min_len_slug - part_history.chapter.len());
print!("{}", series_config.prepub_community.name); print!("{}", series_config.prepub_community.name);
println!("{:<1$}|", "", 20 - series_config.prepub_community.name.len()); println!("{:<1$}|", "", 20 - series_config.prepub_community.name.len());
}); }
}); }
println!("{:#<1$}", "", separator_width); println!("{:#<1$}", "", separator_width);
for error in data.get_messages(true, true, false).iter() { for error in data.get_messages(true, true, false).iter() {
println!("{}", error.content()); println!("{}", error.content());