From fac102e6bee7628db9417ba8e5dbad9043f2edc8 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 23 Mar 2022 23:45:54 +0300 Subject: [PATCH] refac: prevent a panic --- src/commands/query.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/query.rs b/src/commands/query.rs index 66b94f9..a96a5ac 100644 --- a/src/commands/query.rs +++ b/src/commands/query.rs @@ -1,5 +1,4 @@ use super::StreamCommand; -use whatlang::{detect}; use crate::result::*; use regex::Regex; @@ -35,9 +34,10 @@ impl StreamCommand for QueryCommand<'_> { } // use greyblake/whatlang-rs to autodect locale - let text = detect(self.terms).unwrap(); - if text.confidence() == 1.0 { - message.push_str(&format!(" LANG({})", text.lang().code())); + if let Some(info) = whatlang::detect(self.terms) { + if info.confidence() == 1.0 { + message.push_str(&format!(" LANG({})", info.lang().code())); + } } message.push_str("\r\n");