From fb09f071b2153816102236fac0590ca8898a5bcf Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Mon, 23 Oct 2023 16:12:00 -0400 Subject: [PATCH] fix(core): provide better error message if we cannot read a file when finding imports --- .../native/plugins/js/ts_import_locators.rs | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/nx/src/native/plugins/js/ts_import_locators.rs b/packages/nx/src/native/plugins/js/ts_import_locators.rs index 80262cd412db2f..c7ebdcd96d3ff7 100644 --- a/packages/nx/src/native/plugins/js/ts_import_locators.rs +++ b/packages/nx/src/native/plugins/js/ts_import_locators.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use std::collections::{HashMap, HashSet}; use std::fmt::Debug; use std::path::Path; @@ -443,11 +444,13 @@ fn find_specifier_in_require(state: &mut State) -> Option<(String, ImportType)> None } -fn process_file((source_project, file_path): (&String, &String)) -> Option { +fn process_file( + (source_project, file_path): (&String, &String), +) -> anyhow::Result> { let now = Instant::now(); let cm = Arc::::default() .load_file(Path::new(file_path)) - .unwrap(); + .map_err(|e| anyhow!("Unable to load {}: {}", file_path, e))?; let comments = SingleThreadedComments::default(); @@ -573,16 +576,18 @@ fn process_file((source_project, file_path): (&String, &String)) -> Option>) -> Vec { +fn find_imports( + project_file_map: HashMap>, +) -> anyhow::Result> { enable_logger(); let files_to_process: Vec<(&String, &String)> = project_file_map @@ -592,7 +597,7 @@ fn find_imports(project_file_map: HashMap>) -> Vec