From 13a63f277c39af175ebeebf8ff7a064bf20dddb4 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sun, 6 Nov 2022 23:23:34 +0100 Subject: [PATCH] Fix some unwrap's --- Cargo.lock | 75 +++++++++++--------- src/bots/approved_bot/modules/annotations.rs | 7 +- src/bots_manager.rs | 7 +- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b72a27f..26ede66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,9 +207,9 @@ checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "cfg-if" @@ -688,9 +688,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" dependencies = [ "bytes", "futures-channel", @@ -725,9 +725,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.51" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -784,9 +784,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" [[package]] name = "itertools" @@ -899,9 +899,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -954,23 +954,14 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", ] -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - [[package]] name = "object" version = "0.29.0" @@ -982,9 +973,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "openssl" @@ -1077,9 +1068,9 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-error" @@ -1173,9 +1164,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -1184,9 +1175,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remove_dir_all" @@ -1389,7 +1380,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "time 0.3.15", + "time 0.3.17", "url", "uuid", ] @@ -1677,13 +1668,29 @@ dependencies = [ [[package]] name = "time" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ "itoa", - "libc", - "num_threads", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + +[[package]] +name = "time-macros" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" +dependencies = [ + "time-core", ] [[package]] diff --git a/src/bots/approved_bot/modules/annotations.rs b/src/bots/approved_bot/modules/annotations.rs index 68228a8..54846d4 100644 --- a/src/bots/approved_bot/modules/annotations.rs +++ b/src/bots/approved_bot/modules/annotations.rs @@ -27,7 +27,8 @@ pub enum AnnotationCommand { impl CommandParse for AnnotationCommand { fn parse(s: &str, bot_name: &str) -> Result { - let re = Regex::new(r"^/(?Pa|b)_an_(?P\d+)$").unwrap(); + let re = Regex::new(r"^/(?Pa|b)_an_(?P\d+)$") + .unwrap_or_else(|_| panic!("Can't create AnnotationCommand regexp!")); let full_bot_name = format!("@{bot_name}"); let after_replace = s.replace(&full_bot_name, ""); @@ -39,7 +40,9 @@ impl CommandParse for AnnotationCommand { }; let annotation_type = &caps["an_type"]; - let id: u32 = caps["id"].parse().unwrap(); + let id: u32 = caps["id"] + .parse() + .unwrap_or_else(|_| panic!("Can't get id from AnnotationCommand!")); match annotation_type { "a" => Ok(AnnotationCommand::Author { id }), diff --git a/src/bots_manager.rs b/src/bots_manager.rs index af14443..3da9c72 100644 --- a/src/bots_manager.rs +++ b/src/bots_manager.rs @@ -78,12 +78,15 @@ impl BotsManager { .auto_send(); let token = bot.inner().token(); - let port = self.bot_port_map.get(&bot_data.id).unwrap(); + let port = self.bot_port_map + .get(&bot_data.id) + .unwrap_or_else(|| panic!("Can't get bot port!")); let addr = ([0, 0, 0, 0], *port).into(); let host = format!("{}:{}", &config::CONFIG.webhook_base_url, port); - let url = Url::parse(&format!("{host}/{token}")).unwrap(); + let url = Url::parse(&format!("{host}/{token}")) + .unwrap_or_else(|_| panic!("Can't parse webhook url!")); log::info!( "Start bot(id={}) with {:?} handler, port {}",