Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When there are special characters in xml, vue, html, etc., loc will panic, causing the process to exit and statistics to fail. The patch ignores the error file. #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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,
});
}
}
}
};
Expand Down