From 329a8ae0c098619c8f976f2035e5599094cb43f4 Mon Sep 17 00:00:00 2001 From: Evan <96965321+0xIchigo@users.noreply.github.com> Date: Mon, 13 May 2024 17:18:38 -0400 Subject: fix(cli): panic with `deno coverage` (#23353) This PR directly addresses the issue raised in #23282 where Deno panics if `deno coverage` is called with `--include` regex that returns no matches. I've opted not to change the return value of `collect_summary` for simplicity and return an empty `HashMap` instead --- cli/tools/coverage/reporter.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cli/tools/coverage/reporter.rs') diff --git a/cli/tools/coverage/reporter.rs b/cli/tools/coverage/reporter.rs index f6f8144a4..6547f2036 100644 --- a/cli/tools/coverage/reporter.rs +++ b/cli/tools/coverage/reporter.rs @@ -52,7 +52,12 @@ pub trait CoverageReporter { file_reports: &'a Vec<(CoverageReport, String)>, ) -> CoverageSummary { let urls = file_reports.iter().map(|rep| &rep.0.url).collect(); - let root = util::find_root(urls).unwrap().to_file_path().unwrap(); + let root = match util::find_root(urls) + .and_then(|root_path| root_path.to_file_path().ok()) + { + Some(path) => path, + None => return HashMap::new(), + }; // summary by file or directory // tuple of (line hit, line miss, branch hit, branch miss, parent) let mut summary = HashMap::new(); -- cgit v1.2.3