From ba2f57ad1b9ab0c8fa436a66142235585630f48d Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Mon, 27 Dec 2021 16:44:34 -0600 Subject: [PATCH] Use a Result instead of expecting --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index fc12375..7984dd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,7 +117,7 @@ async fn main() -> anyhow::Result<()> { data.insert::(irc_client.sender()); } - let webhook = parse_webhook_url(http.clone(), webhook).await; + let webhook = parse_webhook_url(http.clone(), webhook).await.expect("Invalid webhook URL"); tokio::spawn(async move { irc_loop(irc_client, http, channel_id, webhook).await.unwrap(); @@ -160,15 +160,15 @@ async fn irc_loop( Ok(()) } -async fn parse_webhook_url(http: Arc, url: Option) -> Option { +async fn parse_webhook_url(http: Arc, url: Option) -> anyhow::Result> { if let Some(url) = url { let url = url.trim_start_matches("https://discord.com/api/webhooks/"); let split = url.split("/").collect::>(); - let id = split[0].parse::().expect("Invalid webhook URL"); + let id = split[0].parse::()?; let token = split[1].to_string(); - let webhook = http.get_webhook_with_token(id, &token).await.expect("Invalid webhook URL"); - Some(webhook) + let webhook = http.get_webhook_with_token(id, &token).await?; + Ok(Some(webhook)) } else { - None + Ok(None) } } \ No newline at end of file