Skip to content

Commit 4cec3e0

Browse files
committed
harden error handling
1 parent db75901 commit 4cec3e0

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/cli/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,24 @@ impl Args {
3636

3737
#[cfg(all(windows, not(debug_assertions)))]
3838
if let Some(logs_file) = crate::utils::formatted_strings::get_logs_file_path() {
39+
use crate::utils::error_logger::{ErrorLogger, Location};
3940
if args.logs {
40-
std::process::Command::new("explorer")
41+
if let Ok(mut explorer) = std::process::Command::new("explorer")
4142
.arg(logs_file)
4243
.spawn()
43-
.unwrap()
44-
.wait()
45-
.unwrap_or_default();
46-
std::process::exit(0);
44+
.log_err(crate::location!())
45+
{
46+
let _ = explorer.wait().log_err(crate::location!());
47+
std::process::exit(0);
48+
}
49+
std::process::exit(1);
4750
} else {
4851
// truncate logs file
4952
let _ = std::fs::OpenOptions::new()
5053
.write(true)
5154
.truncate(true)
52-
.open(logs_file);
55+
.open(logs_file)
56+
.log_err(crate::location!());
5357
}
5458
}
5559

src/networking/types/info_traffic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ impl InfoTraffic {
9898
DataRepr::Packets => u128::from(self.dropped_packets),
9999
DataRepr::Bytes | DataRepr::Bits => {
100100
// assume that the dropped packets have the same size as the average packet
101-
u128::from(self.dropped_packets) * all / all_packets
101+
u128::from(self.dropped_packets)
102+
.saturating_mul(all)
103+
.checked_div(all_packets)
104+
.unwrap_or_default()
102105
}
103106
};
104107

src/notifications/types/notifications.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ impl DataNotification {
103103
let without_multiple: String = chars[0..chars.len() - 1].iter().collect();
104104
if without_multiple.parse::<u64>().is_ok()
105105
&& TryInto::<u64>::try_into(
106-
without_multiple.parse::<u128>().unwrap_or_default()
107-
* u128::from(byte_multiple_inserted.multiplier()),
106+
without_multiple
107+
.parse::<u128>()
108+
.unwrap_or_default()
109+
.saturating_mul(u128::from(byte_multiple_inserted.multiplier())),
108110
)
109111
.is_ok()
110112
{

src/report/types/report_col.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ impl ReportCol {
4747
ReportCol::Service => service_translation(language).to_string(),
4848
ReportCol::Data => {
4949
let mut str = data_repr.get_label(language).to_string();
50-
str.remove(0).to_uppercase().to_string() + &str
50+
if str.is_empty() {
51+
str
52+
} else {
53+
str.remove(0).to_uppercase().to_string() + &str
54+
}
5155
}
5256
}
5357
}

0 commit comments

Comments
 (0)