Skip to content

Commit

Permalink
Promote an assert! to a bail!
Browse files Browse the repository at this point in the history
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 bytecodealliance#1996
  • Loading branch information
alexcrichton committed Feb 25, 2025
1 parent b4967c4 commit ed52cbd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/wit-parser/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,13 @@ impl Remap {
worlds: Default::default(),
});
let prev = resolve.package_names.insert(unresolved.name.clone(), pkgid);
assert!(prev.is_none());
if let Some(prev) = prev {
resolve.package_names.insert(unresolved.name.clone(), prev);
bail!(
"attempting to re-add package `{}` when it's already present in this `Resolve`",
unresolved.name,
);
}

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

Expand Down

0 comments on commit ed52cbd

Please sign in to comment.