diff options
author | andy.boot <bootandy@gmail.com> | 2022-08-26 17:08:46 +0100 |
---|---|---|
committer | andy.boot <bootandy@gmail.com> | 2022-08-26 17:12:39 +0100 |
commit | 137bde1099302ad09e625d887a1ee9c85db94021 (patch) | |
tree | 50e41be173384577074d951a1d63890137842247 | |
parent | 0d0206a5a5f28b29a1bb11cb039780aa7df6f399 (diff) |
Fix: Try to stop panics on android.fix_error_on_thread_creation3
Catch panics on thread initialization.
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index ca95236..df99a96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod utils; use crate::cli::build_cli; use std::collections::HashSet; +use std::panic; use std::process; use self::display::draw_it; @@ -19,6 +20,7 @@ use config::get_config; use dir_walker::{walk_it, WalkData}; use filter::get_biggest; use filter_type::get_all_file_types; +use rayon::ThreadPoolBuildError; use regex::Regex; use std::cmp::max; use std::path::PathBuf; @@ -154,11 +156,10 @@ fn main() { by_filecount, ignore_hidden: config.get_ignore_hidden(&options), }; - // Larger stack size to handle cases with lots of nested directories - rayon::ThreadPoolBuilder::new() - .stack_size(usize::pow(1024, 3)) - .build_global() - .unwrap_or_else(|e| eprintln!("Warning: Could not configure threads {:?}", e)); + let pool = panic::catch_unwind(init_rayon); + if pool.is_err() { + eprintln!("Warning: Could not configure threads {:?}", pool.err()); + } let iso = config.get_iso(&options); let (top_level_nodes, has_errors) = walk_it(simplified_dirs, walk_data); @@ -191,3 +192,10 @@ fn main() { ) } } + +fn init_rayon() -> Result<(), ThreadPoolBuildError> { + // Larger stack size to handle cases with lots of nested directories + rayon::ThreadPoolBuilder::new() + .stack_size(usize::pow(1024, 3)) + .build_global() +} |