From d596e6c092220968cbb5bf0879d43dfdad3e0d6e Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Mon, 10 Feb 2025 14:36:41 +0000 Subject: [PATCH] move-build: Informative duplicate module error ## Description If we find a duplicate module when creating a `Modules` map, include the module's ID in the output. ## Test plan Hit this error when debugging something else. --- .../move/crates/move-bytecode-utils/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/external-crates/move/crates/move-bytecode-utils/src/lib.rs b/external-crates/move/crates/move-bytecode-utils/src/lib.rs index c2af29e185dd64..456ef27c2fb800 100644 --- a/external-crates/move/crates/move-bytecode-utils/src/lib.rs +++ b/external-crates/move/crates/move-bytecode-utils/src/lib.rs @@ -25,10 +25,12 @@ impl<'a> Modules<'a> { pub fn new(modules: impl IntoIterator) -> Self { let mut map = BTreeMap::new(); for m in modules { - assert!( - map.insert(m.self_id(), m).is_none(), - "Duplicate module found" - ); + if let Some(prev) = map.insert(m.self_id(), m) { + panic!( + "Duplicate module found: {}", + prev.self_id().to_canonical_display(/* with_prefix */ true) + ) + } } Modules(map) }