From b1230a85e8ba63f3542892711043cefdc916acf8 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 30 Dec 2020 22:19:51 +1100 Subject: [PATCH] fix(cli): info does not panic on missing modules (#8924) Fixes #8918 --- cli/module_graph.rs | 12 +++++++----- cli/tests/info_missing_module.out | 2 ++ cli/tests/integration_tests.rs | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 cli/tests/info_missing_module.out diff --git a/cli/module_graph.rs b/cli/module_graph.rs index be0f428b4e..c8bd3d1f39 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -1107,11 +1107,13 @@ impl Graph { totals: &mut HashMap, ) -> ModuleInfo { let not_seen = seen.insert(specifier.clone()); - let module = if let ModuleSlot::Module(module) = self.get_module(specifier) - { - module - } else { - unreachable!(); + let module = match self.get_module(specifier) { + ModuleSlot::Module(module) => module, + ModuleSlot::Err(err) => { + error!("{}: {}", colors::red_bold("error"), err.to_string()); + std::process::exit(1); + } + _ => unreachable!(), }; let mut deps = Vec::new(); let mut total_size = None; diff --git a/cli/tests/info_missing_module.out b/cli/tests/info_missing_module.out new file mode 100644 index 0000000000..fd9b9b7638 --- /dev/null +++ b/cli/tests/info_missing_module.out @@ -0,0 +1,2 @@ +error: Cannot resolve module "file://[WILDCARD]/bad-module.js" from "file://[WILDCARD]/error_009_missing_js_module.js". + at file://[WILDCARD]/error_009_missing_js_module.js:1:0 diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index a0827ff686..9400db4add 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -3407,6 +3407,12 @@ itest!(import_file_with_colon { http_server: true, }); +itest!(info_missing_module { + args: "info error_009_missing_js_module.js", + output: "info_missing_module.out", + exit_code: 1, +}); + itest!(info_recursive_modules { args: "info --quiet info_recursive_imports_test.ts", output: "info_recursive_imports_test.out",