Skip to content

Commit

Permalink
Improve name lookup for trappable_error_type configuration (#8833)
Browse files Browse the repository at this point in the history
This commit improves the experience around using the
`trappable_error_type` configuration by fixing two issues:

* When an error can't be resolved it doesn't result in a
  `unwrap()`, instead a first-class error is returned to get reported.

* The name lookup procedure is now consistent with the name lookup that
  the `with` key does, notably allowing the version to be optional but
  still supporting the version.

This fixes an issue that came up recently where a path with a version
was specified but the old lookup logic ended up requiring that the
version wasn't specified because there was only one package with that
version. This behavior resulted in a panic with a very long
backtrace-based error message which was confusing to parse. By returning
an error the error is much more succinct and by supporting more names
the original intuition will work.
  • Loading branch information
alexcrichton authored Jun 18, 2024
1 parent b3636ff commit 5f3597e
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 200 deletions.
47 changes: 47 additions & 0 deletions crates/component-macro/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,50 @@ mod with_and_mixing_async {
});
}
}

mod trappable_error_type_and_versions {
struct MyError;

mod package_no_version_path_no_version {
wasmtime::component::bindgen!({
inline: "
package my:inline;
interface i {
enum e { a, b, c }
}
world foo {}
",
trappable_error_type: {
"my:inline/i/e" => super::MyError,
},
});
}
mod package_version_path_no_version {
wasmtime::component::bindgen!({
inline: "
package my:inline@1.0.0;
interface i {
enum e { a, b, c }
}
world foo {}
",
trappable_error_type: {
"my:inline/i/e" => super::MyError,
},
});
}
mod package_version_path_version {
wasmtime::component::bindgen!({
inline: "
package my:inline@1.0.0;
interface i {
enum e { a, b, c }
}
world foo {}
",
trappable_error_type: {
"my:inline/i@1.0.0/e" => super::MyError,
},
});
}
}
Loading

0 comments on commit 5f3597e

Please sign in to comment.