From f35b3468ee0fe928b472a47a13b2dd0dcf37bb46 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 16 Jun 2023 01:05:12 +0100 Subject: [PATCH] fix(frontend): Avoid panic if dependency cannot be resolved (#1719) --- crates/noirc_frontend/src/hir/resolution/import.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/noirc_frontend/src/hir/resolution/import.rs b/crates/noirc_frontend/src/hir/resolution/import.rs index 79176d74afc..0bc7e065adb 100644 --- a/crates/noirc_frontend/src/hir/resolution/import.rs +++ b/crates/noirc_frontend/src/hir/resolution/import.rs @@ -192,11 +192,11 @@ fn resolve_external_dep( let path = &directive.path.segments; // // Fetch the root module from the prelude - let crate_name = path.first().unwrap().0.contents.clone(); + let crate_name = path.first().unwrap(); let dep_module = current_def_map .extern_prelude - .get(&crate_name) - .unwrap_or_else(|| panic!("error reporter: could not find crate {crate_name}")); + .get(&crate_name.0.contents) + .ok_or_else(|| PathResolutionError::Unresolved(crate_name.to_owned()))?; // Create an import directive for the dependency crate let path_without_crate_name = &path[1..]; // XXX: This will panic if the path is of the form `use dep::std` Ideal algorithm will not distinguish between crate and module