Skip to content

Commit 9b06a14

Browse files
committed
Migrate the wasmtime crate to wasmtime_internal_error::Error
Instead of `anyhow::Error`. This commit re-exports the `wasmtime_internal_error` crate as the `wasmtime::error` module, updates the prelude to include these new error-handling types, redirects our top-level `wasmtime::{Error, Result}` re-exports to re-export `wasmtime::error::{Error, Result}`, and updates various use sites that were directly using `anyhow` to use the new `wasmtime` versions. This process also required updating the component macro and wit-bindgen macro to use the new error types instead of `anyhow`. Part of #12069
1 parent b5272a5 commit 9b06a14

File tree

197 files changed

+809
-1003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+809
-1003
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/component-macro/src/component.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ fn expand_record_for_component_type(
413413
fn typecheck(
414414
ty: &#internal::InterfaceType,
415415
types: &#internal::InstanceType<'_>,
416-
) -> #internal::anyhow::Result<()> {
416+
) -> #wt::error::Result<()> {
417417
#internal::#typecheck(ty, types, &[#typecheck_argument])
418418
}
419419
}
@@ -489,7 +489,7 @@ impl Expander for LiftExpander {
489489
cx: &mut #internal::LiftContext<'_>,
490490
ty: #internal::InterfaceType,
491491
src: &Self::Lower,
492-
) -> #internal::anyhow::Result<Self> {
492+
) -> #wt::error::Result<Self> {
493493
#extract_ty
494494
Ok(Self {
495495
#lifts
@@ -501,7 +501,7 @@ impl Expander for LiftExpander {
501501
cx: &mut #internal::LiftContext<'_>,
502502
ty: #internal::InterfaceType,
503503
bytes: &[u8],
504-
) -> #internal::anyhow::Result<Self> {
504+
) -> #wt::error::Result<Self> {
505505
#extract_ty
506506
debug_assert!(
507507
(bytes.as_ptr() as usize)
@@ -580,11 +580,11 @@ impl Expander for LiftExpander {
580580
cx: &mut #internal::LiftContext<'_>,
581581
ty: #internal::InterfaceType,
582582
src: &Self::Lower,
583-
) -> #internal::anyhow::Result<Self> {
583+
) -> #wt::error::Result<Self> {
584584
#extract_ty
585585
Ok(match src.tag.get_u32() {
586586
#lifts
587-
discrim => #internal::anyhow::bail!("unexpected discriminant: {}", discrim),
587+
discrim => #wt::error::bail!("unexpected discriminant: {}", discrim),
588588
})
589589
}
590590

@@ -593,7 +593,7 @@ impl Expander for LiftExpander {
593593
cx: &mut #internal::LiftContext<'_>,
594594
ty: #internal::InterfaceType,
595595
bytes: &[u8],
596-
) -> #internal::anyhow::Result<Self> {
596+
) -> #wt::error::Result<Self> {
597597
let align = <Self as #wt::component::ComponentType>::ALIGN32;
598598
debug_assert!((bytes.as_ptr() as usize) % (align as usize) == 0);
599599
let discrim = #from_bytes;
@@ -602,7 +602,7 @@ impl Expander for LiftExpander {
602602
#extract_ty
603603
Ok(match discrim {
604604
#loads
605-
discrim => #internal::anyhow::bail!("unexpected discriminant: {}", discrim),
605+
discrim => #wt::error::bail!("unexpected discriminant: {}", discrim),
606606
})
607607
}
608608
}
@@ -647,11 +647,11 @@ impl Expander for LiftExpander {
647647
cx: &mut #internal::LiftContext<'_>,
648648
ty: #internal::InterfaceType,
649649
src: &Self::Lower,
650-
) -> #internal::anyhow::Result<Self> {
650+
) -> #wt::error::Result<Self> {
651651
#extract_ty
652652
let discrim = src.tag.get_u32();
653653
if discrim >= #discrim_limit {
654-
#internal::anyhow::bail!("unexpected discriminant: {discrim}");
654+
#wt::error::bail!("unexpected discriminant: {discrim}");
655655
}
656656
Ok(unsafe {
657657
#internal::transmute::<#discrim_ty, #name>(discrim as #discrim_ty)
@@ -663,12 +663,12 @@ impl Expander for LiftExpander {
663663
cx: &mut #internal::LiftContext<'_>,
664664
ty: #internal::InterfaceType,
665665
bytes: &[u8],
666-
) -> #internal::anyhow::Result<Self> {
666+
) -> #wt::error::Result<Self> {
667667
let align = <Self as #wt::component::ComponentType>::ALIGN32;
668668
debug_assert!((bytes.as_ptr() as usize) % (align as usize) == 0);
669669
let discrim = #from_bytes;
670670
if u32::from(discrim) >= #discrim_limit {
671-
#internal::anyhow::bail!("unexpected discriminant: {discrim}");
671+
#wt::error::bail!("unexpected discriminant: {discrim}");
672672
}
673673
Ok(unsafe {
674674
#internal::transmute::<#discrim_ty, #name>(discrim)
@@ -728,7 +728,7 @@ impl Expander for LowerExpander {
728728
cx: &mut #internal::LowerContext<'_, T>,
729729
ty: #internal::InterfaceType,
730730
dst: &mut core::mem::MaybeUninit<Self::Lower>,
731-
) -> #internal::anyhow::Result<()> {
731+
) -> #wt::error::Result<()> {
732732
#extract_ty
733733
#lowers
734734
Ok(())
@@ -740,7 +740,7 @@ impl Expander for LowerExpander {
740740
cx: &mut #internal::LowerContext<'_, T>,
741741
ty: #internal::InterfaceType,
742742
mut offset: usize
743-
) -> #internal::anyhow::Result<()> {
743+
) -> #wt::error::Result<()> {
744744
debug_assert!(offset % (<Self as #wt::component::ComponentType>::ALIGN32 as usize) == 0);
745745
#extract_ty
746746
#stores
@@ -826,7 +826,7 @@ impl Expander for LowerExpander {
826826
cx: &mut #internal::LowerContext<'_, T>,
827827
ty: #internal::InterfaceType,
828828
dst: &mut core::mem::MaybeUninit<Self::Lower>,
829-
) -> #internal::anyhow::Result<()> {
829+
) -> #wt::error::Result<()> {
830830
#extract_ty
831831
match self {
832832
#lowers
@@ -839,7 +839,7 @@ impl Expander for LowerExpander {
839839
cx: &mut #internal::LowerContext<'_, T>,
840840
ty: #internal::InterfaceType,
841841
mut offset: usize
842-
) -> #internal::anyhow::Result<()> {
842+
) -> #wt::error::Result<()> {
843843
#extract_ty
844844
debug_assert!(offset % (<Self as #wt::component::ComponentType>::ALIGN32 as usize) == 0);
845845
match self {
@@ -883,7 +883,7 @@ impl Expander for LowerExpander {
883883
cx: &mut #internal::LowerContext<'_, T>,
884884
ty: #internal::InterfaceType,
885885
dst: &mut core::mem::MaybeUninit<Self::Lower>,
886-
) -> #internal::anyhow::Result<()> {
886+
) -> #wt::error::Result<()> {
887887
#extract_ty
888888
#internal::map_maybe_uninit!(dst.tag)
889889
.write(#wt::ValRaw::u32(*self as u32));
@@ -896,7 +896,7 @@ impl Expander for LowerExpander {
896896
cx: &mut #internal::LowerContext<'_, T>,
897897
ty: #internal::InterfaceType,
898898
mut offset: usize
899-
) -> #internal::anyhow::Result<()> {
899+
) -> #wt::error::Result<()> {
900900
#extract_ty
901901
debug_assert!(offset % (<Self as #wt::component::ComponentType>::ALIGN32 as usize) == 0);
902902
let discrim = *self as #ty;
@@ -1026,7 +1026,7 @@ impl Expander for ComponentTypeExpander {
10261026
fn typecheck(
10271027
ty: &#internal::InterfaceType,
10281028
types: &#internal::InstanceType<'_>,
1029-
) -> #internal::anyhow::Result<()> {
1029+
) -> #wt::error::Result<()> {
10301030
#internal::typecheck_variant(ty, types, &[#case_names_and_checks])
10311031
}
10321032

@@ -1087,7 +1087,7 @@ impl Expander for ComponentTypeExpander {
10871087
fn typecheck(
10881088
ty: &#internal::InterfaceType,
10891089
types: &#internal::InstanceType<'_>,
1090-
) -> #internal::anyhow::Result<()> {
1090+
) -> #wt::error::Result<()> {
10911091
#internal::typecheck_enum(ty, types, &[#case_names])
10921092
}
10931093

@@ -1472,7 +1472,7 @@ pub fn expand_flags(flags: &Flags) -> Result<TokenStream> {
14721472
cx: &mut #internal::LowerContext<'_, T>,
14731473
_ty: #internal::InterfaceType,
14741474
dst: &mut core::mem::MaybeUninit<Self::Lower>,
1475-
) -> #internal::anyhow::Result<()> {
1475+
) -> #wt::error::Result<()> {
14761476
#(
14771477
self.#field_names.linear_lower_to_flat(
14781478
cx,
@@ -1488,7 +1488,7 @@ pub fn expand_flags(flags: &Flags) -> Result<TokenStream> {
14881488
cx: &mut #internal::LowerContext<'_, T>,
14891489
_ty: #internal::InterfaceType,
14901490
mut offset: usize
1491-
) -> #internal::anyhow::Result<()> {
1491+
) -> #wt::error::Result<()> {
14921492
debug_assert!(offset % (<Self as #wt::component::ComponentType>::ALIGN32 as usize) == 0);
14931493
#(
14941494
self.#field_names.linear_lower_to_memory(
@@ -1507,7 +1507,7 @@ pub fn expand_flags(flags: &Flags) -> Result<TokenStream> {
15071507
cx: &mut #internal::LiftContext<'_>,
15081508
_ty: #internal::InterfaceType,
15091509
src: &Self::Lower,
1510-
) -> #internal::anyhow::Result<Self> {
1510+
) -> #wt::error::Result<Self> {
15111511
Ok(Self {
15121512
#(
15131513
#field_names: #wt::component::Lift::linear_lift_from_flat(
@@ -1523,7 +1523,7 @@ pub fn expand_flags(flags: &Flags) -> Result<TokenStream> {
15231523
cx: &mut #internal::LiftContext<'_>,
15241524
_ty: #internal::InterfaceType,
15251525
bytes: &[u8],
1526-
) -> #internal::anyhow::Result<Self> {
1526+
) -> #wt::error::Result<Self> {
15271527
debug_assert!(
15281528
(bytes.as_ptr() as usize)
15291529
% (<Self as #wt::component::ComponentType>::ALIGN32 as usize)

crates/component-macro/tests/codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ macro_rules! gentest {
4343
component_macro_test_helpers::foreach!(gentest);
4444

4545
mod with_key_and_resources {
46-
use anyhow::Result;
4746
use wasmtime::component::Resource;
47+
use wasmtime::error::Result;
4848

4949
wasmtime::component::bindgen!({
5050
inline: "

crates/component-macro/tests/expanded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22

3-
use anyhow::{Context, Result, bail};
3+
use wasmtime::error::{Context, Result, bail};
44

55
macro_rules! genexpand {
66
($id:ident $name:tt $path:tt) => {

crates/component-macro/tests/expanded/char.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ pub struct TheWorld {
103103
interface0: exports::foo::foo::chars::Guest,
104104
}
105105
const _: () = {
106-
#[allow(unused_imports)]
107-
use wasmtime::component::__internal::anyhow;
108106
impl TheWorldIndices {
109107
/// Creates a new copy of `TheWorldIndices` bindings which can then
110108
/// be used to instantiate into a particular store.
@@ -190,7 +188,7 @@ pub mod foo {
190188
#[allow(clippy::all)]
191189
pub mod chars {
192190
#[allow(unused_imports)]
193-
use wasmtime::component::__internal::{anyhow, Box};
191+
use wasmtime::component::__internal::Box;
194192
pub trait HostWithStore: wasmtime::component::HasData {}
195193
impl<_T: ?Sized> HostWithStore for _T
196194
where
@@ -252,7 +250,7 @@ pub mod exports {
252250
#[allow(clippy::all)]
253251
pub mod chars {
254252
#[allow(unused_imports)]
255-
use wasmtime::component::__internal::{anyhow, Box};
253+
use wasmtime::component::__internal::Box;
256254
#[derive(Clone)]
257255
pub struct Guest {
258256
take_char: wasmtime::component::Func,
@@ -277,7 +275,7 @@ pub mod exports {
277275
.component()
278276
.get_export_index(None, "foo:foo/chars")
279277
.ok_or_else(|| {
280-
anyhow::anyhow!(
278+
wasmtime::error::format_err!(
281279
"no exported instance named `foo:foo/chars`"
282280
)
283281
})?;
@@ -286,7 +284,7 @@ pub mod exports {
286284
.component()
287285
.get_export_index(Some(&instance), name)
288286
.ok_or_else(|| {
289-
anyhow::anyhow!(
287+
wasmtime::error::format_err!(
290288
"instance export `foo:foo/chars` does \
291289
not have export `{name}`"
292290
)

crates/component-macro/tests/expanded/char_async.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ pub struct TheWorld {
103103
interface0: exports::foo::foo::chars::Guest,
104104
}
105105
const _: () = {
106-
#[allow(unused_imports)]
107-
use wasmtime::component::__internal::anyhow;
108106
impl TheWorldIndices {
109107
/// Creates a new copy of `TheWorldIndices` bindings which can then
110108
/// be used to instantiate into a particular store.
@@ -190,7 +188,7 @@ pub mod foo {
190188
#[allow(clippy::all)]
191189
pub mod chars {
192190
#[allow(unused_imports)]
193-
use wasmtime::component::__internal::{anyhow, Box};
191+
use wasmtime::component::__internal::Box;
194192
pub trait HostWithStore: wasmtime::component::HasData + Send {}
195193
impl<_T: ?Sized> HostWithStore for _T
196194
where
@@ -266,7 +264,7 @@ pub mod exports {
266264
#[allow(clippy::all)]
267265
pub mod chars {
268266
#[allow(unused_imports)]
269-
use wasmtime::component::__internal::{anyhow, Box};
267+
use wasmtime::component::__internal::Box;
270268
#[derive(Clone)]
271269
pub struct Guest {
272270
take_char: wasmtime::component::Func,
@@ -291,7 +289,7 @@ pub mod exports {
291289
.component()
292290
.get_export_index(None, "foo:foo/chars")
293291
.ok_or_else(|| {
294-
anyhow::anyhow!(
292+
wasmtime::error::format_err!(
295293
"no exported instance named `foo:foo/chars`"
296294
)
297295
})?;
@@ -300,7 +298,7 @@ pub mod exports {
300298
.component()
301299
.get_export_index(Some(&instance), name)
302300
.ok_or_else(|| {
303-
anyhow::anyhow!(
301+
wasmtime::error::format_err!(
304302
"instance export `foo:foo/chars` does \
305303
not have export `{name}`"
306304
)

crates/component-macro/tests/expanded/char_concurrent.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ pub struct TheWorld {
103103
interface0: exports::foo::foo::chars::Guest,
104104
}
105105
const _: () = {
106-
#[allow(unused_imports)]
107-
use wasmtime::component::__internal::anyhow;
108106
impl TheWorldIndices {
109107
/// Creates a new copy of `TheWorldIndices` bindings which can then
110108
/// be used to instantiate into a particular store.
@@ -190,7 +188,7 @@ pub mod foo {
190188
#[allow(clippy::all)]
191189
pub mod chars {
192190
#[allow(unused_imports)]
193-
use wasmtime::component::__internal::{anyhow, Box};
191+
use wasmtime::component::__internal::Box;
194192
pub trait HostWithStore: wasmtime::component::HasData + Send {
195193
/// A function that accepts a character
196194
fn take_char<T>(
@@ -245,7 +243,7 @@ pub mod exports {
245243
#[allow(clippy::all)]
246244
pub mod chars {
247245
#[allow(unused_imports)]
248-
use wasmtime::component::__internal::{anyhow, Box};
246+
use wasmtime::component::__internal::Box;
249247
#[derive(Clone)]
250248
pub struct Guest {
251249
take_char: wasmtime::component::Func,
@@ -270,7 +268,7 @@ pub mod exports {
270268
.component()
271269
.get_export_index(None, "foo:foo/chars")
272270
.ok_or_else(|| {
273-
anyhow::anyhow!(
271+
wasmtime::error::format_err!(
274272
"no exported instance named `foo:foo/chars`"
275273
)
276274
})?;
@@ -279,7 +277,7 @@ pub mod exports {
279277
.component()
280278
.get_export_index(Some(&instance), name)
281279
.ok_or_else(|| {
282-
anyhow::anyhow!(
280+
wasmtime::error::format_err!(
283281
"instance export `foo:foo/chars` does \
284282
not have export `{name}`"
285283
)

0 commit comments

Comments
 (0)