From 6fefda80582eafac1fc8c5b6fd74cb848c7fa11b Mon Sep 17 00:00:00 2001 From: "caofx0418@163.com" Date: Fri, 15 Apr 2022 23:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93xml=E4=B8=AD=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E6=97=B6=EF=BC=8Cloc?= =?UTF-8?q?=E5=B0=86panic=EF=BC=8C=E4=BB=8E=E8=80=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=A4=B1=E8=B4=A5=E3=80=82=E8=AF=A5patch?= =?UTF-8?q?=E5=B0=86=E5=BF=BD=E7=95=A5=E8=AF=A5=E9=94=99=E8=AF=AF=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index e58e790..b6da734 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use std::str::FromStr; use deque::{Stealer, Stolen}; use regex::Regex; use edit_distance::edit_distance as distance; +use std::panic; use loc::*; @@ -50,12 +51,19 @@ impl Worker { Stolen::Data(Work::File(path)) => { let lang = lang_from_ext(&path); if lang != Lang::Unrecognized { - let count = count(&path); - v.push(FileCount { - lang, - path, - count, + panic::set_hook(Box::new(|_info| { + // do nothing + })); + let result = panic::catch_unwind(|| { + count(&path) }); + if let Ok(count) = result { + v.push(FileCount { + lang, + path, + count, + }); + } } } };