Skip to content

Commit d405d00

Browse files
authored
Promote an assert! to a bail! (#2071)
This commit fixes a runtime assertion tripping to instead being a first-class error returned by `bail!`. This cannot currently be triggered from the CLI and is only reachable through API usage of the `wit_parser::Resolve` type. This usage is reachable through generators such as `wit_bindgen::generate!`, though. The error here happens when a package is re-added to a `Resolve` twice. This currently isn't supported and would require some large refactoring to support. This should probably be fixed at some point in the future to actually be supported but until that happens it's best to have a first-class error for this case instead of an internal assertion tripping. Closes #1996
1 parent 90545d4 commit d405d00

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: crates/wit-parser/src/resolve.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,13 @@ impl Remap {
26442644
worlds: Default::default(),
26452645
});
26462646
let prev = resolve.package_names.insert(unresolved.name.clone(), pkgid);
2647-
assert!(prev.is_none());
2647+
if let Some(prev) = prev {
2648+
resolve.package_names.insert(unresolved.name.clone(), prev);
2649+
bail!(
2650+
"attempting to re-add package `{}` when it's already present in this `Resolve`",
2651+
unresolved.name,
2652+
);
2653+
}
26482654

26492655
self.process_foreign_deps(resolve, pkgid, &unresolved)?;
26502656

0 commit comments

Comments
 (0)