fitzgen requested alexcrichton for a review on PR #12231.
fitzgen opened PR #12231 from fitzgen:migrate-wasmtime-to-wasmtime-error to bytecodealliance:main:
Instead of
anyhow::Error.This commit re-exports the
wasmtime_internal_errorcrate as thewasmtime::errormodule, updates the prelude to include these new error-handling types, redirects our top-levelwasmtime::{Error, Result}re-exports to re-exportwasmtime::error::{Error, Result}, and updates various use sites that were directly usinganyhowto use the newwasmtimeversions.This process also required updating the component macro and wit-bindgen macro to use the new error types instead of
anyhow.Part of https://github.com/bytecodealliance/wasmtime/issues/12069
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
fitzgen requested wasmtime-core-reviewers for a review on PR #12231.
fitzgen requested wasmtime-default-reviewers for a review on PR #12231.
fitzgen updated PR #12231.
fitzgen updated PR #12231.
fitzgen edited PR #12231.
fitzgen edited PR #12231:
Instead of
anyhow::Error.This commit re-exports
wasmtime_environ::erroras thewasmtime::errormodule, updates the prelude to include these new error-handling types, redirects our top-levelwasmtime::{Error, Result}re-exports to re-exportwasmtime::error::{Error, Result}, and updates various use sites that were directly usinganyhowto use the newwasmtimeversions.This process also required updating the component macro and wit-bindgen macro to use the new error types instead of
anyhow.Part of https://github.com/bytecodealliance/wasmtime/issues/12069
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton commented on PR #12231:
In retrospect, should we bother with
wasmtime::erroras a module? (vs just having reexports at the top). I would expect almost all uses to go throughwasmtime::Resultinstead ofwasmtime::error::Result(and is something I'd ideally like to see changed in the bindgen output for example).
fitzgen commented on PR #12231:
In retrospect, should we bother with
wasmtime::erroras a module?I think we do want a module because otherwise we would have
wasmtime::Context(instead ofwasmtime::error::Context) which is pretty ambiguous withStoreContextand all that (and we also don't want to renameContextbecause we want to continue to have porting to the new error infra be just flipping the switch fromanyhowtowasmtime-internal-error, which requires API compatibility).
fitzgen commented on PR #12231:
(and is something I'd ideally like to see changed in the bindgen output for example).
Happy to change it, but also this seems like it shouldn't really matter since it is just in macro-expanded code?
alexcrichton commented on PR #12231:
Scattered thought from some more review:
- Migration is happening in incremental steps, so renaming
ContexttoErrorContextisn't out of the question is it? For example nothing is usingwasmtime::Contexttoday or expecting that to work, so having users changeanyhow::Contexttowasmtime::ErrorContextdoesn't seem like a deal-breaker.- It's true yeah that macro-expanded code doesn't matter much, but having two paths to the same type means that it's inevitably going to be used both ways in different places. There are other files modified here which use
crate::error::...instead ofcrate::...for example.- Personally I think that error-handling ergonomics are of a pretty high importance so I want to make sure we're not losing anything in this transition. It's quite easy to throw
anyhow::Foosomewhere for example butwasmtime:::error::Foois much more of a mouthful already. That's where I'd like to keep everything at the crate root ofwasmtime::Fooif we can. That's already still slightly worse than anyhow due to the crate name being longer, but there's not much we can do about that. On example isanyhow::Ok(...)being migrated here towasmtime::error::Ok(...)in a few places which feels overkill to me in terms of "here's a quick type annotation" which has turned into a much longer type annotation
fitzgen commented on PR #12231:
Migration is happening in incremental steps, so renaming
ContexttoErrorContextisn't out of the question is it? For example nothing is usingwasmtime::Contexttoday or expecting that to work, so having users changeanyhow::Contexttowasmtime::ErrorContextdoesn't seem like a deal-breaker.I would say it is 100% a deal-breaker for existing projects that already embed Wasmtime, currently use
anyhow, and will start usingwasmtime::Errorinstead. As long as they are only usinganyhowvia thewasmtime::{Error, Result}aliases today, then the upgrade to Wasmtime that switches away fromanyhowshouldn't involve changing any code at all. But if they are usinganyhowdirectly, for example to get theContexttrait in scope, then they should be able to mechanically replace allanyhow::Foowithwasmtime::error::Foo. The more things we change, the more pain we are causing downstream.Personally I think that error-handling ergonomics are of a pretty high importance so I want to make sure we're not losing anything in this transition.
I agree, which is why I am focusing on not only the Wasmtime developers' ergonomics but also embedders' ergonomics. The best ergonomics is "you don't need to change anything in your existing code and you're already familiar with all the APIs" which is what we get with matching
anyhow's API and have been aiming for this whole time.On example is
anyhow::Ok(...)being migrated here towasmtime::error::Ok(...)in a few places which feels overkill to me in terms of "here's a quick type annotation" which has turned into a much longer type annotationThis is actually another example of why we cannot just export everything at the top level. A ton of our code in examples, tests, and docs do
use wasmtime::*-- and I'm sure that many embedders do that too -- but if we putwasmtime::error::Okatwasmtime::Ok, then that glob import would mean thatwasmtime::Okreplaces the prelude'suse core::result::Result::Ok, which makes things likematching on results break.having two paths to the same type means that it's inevitably going to be used both ways in different places. There are other files modified here which use
crate::error::...instead ofcrate::...for example.Having a top-level alias of an item defined in a nested module seems like a very minor blemish to me. Like I guess in a platonic ideal world it would be nice if it didn't exist, and there was only one path for the item, but it also doesn't seem like it actually hurts at all? Simultaneously, it seems pretty common for crates to re-export the most-common functionality from a nested module to the top level: even
stddoes this with e.g.std::collections::HashMapandstd::collections::hash_map::HashMap.
alexcrichton commented on PR #12231:
Personally I'm not too sold on the downstream churn argument. For example I'd disagree that
anyhow::Foowants to becomewasmtime::error::Foo-- it will work, yes, but ergnomically it's probably not what you want. For the same reason as this PR, I'd rather readwasmtime::Foothanwasmtime::error::Foo(if possible).I would also say that we're teeing up a lot of churn for downstream users because for embeddings it's likely that
anyhowis used pervasively throughout rather than just for Wasmtime which means that conversion fromwasmtime::Errortoanyhow::Errorwill be required (the entire embedding probably won't want to change towasmtime::Result). This'll require updating bindgen-generated traits, for example, to use the right error and any other wasm-y path which flows into Wasmtime. Worse yet all implementations of host functions which generateanyhow::Errorwon't work by-default and will require manual conversions towasmtime::Errordue to coherence. Basically I don't think "minimize churn" is a viable goal/end-state here, it's inevitably going to be a big, painful, change.With this I'd say that the specific context of naming
ErrorContextvsContextis more-or-less irrelevant. If anything it might make it nicer in case you need to have bothanyhow's version andwasmtime's version in scope at the same time. (avoidas _in the import)I guess what I'm getting at is:
The best ergonomics is "you don't need to change anything in your existing code and you're already familiar with all the APIs"
Given two distinct nominal error types (
anyhow::Errorandwasmtime::Error) where you can't auto-convert one to the other (theanyhow::Error => wasmtime::Errordirection) I don't think that this is achievable. Day-to-day usage can have similar ergonomics, but I really don't think that landing this change will be a simple search-and-replace-and-you're-done.
r.e.
wasmtime::Ok-- well damn I'd agree that's probably not possible. Alas.
Having a top-level alias of an item defined in a nested module seems like a very minor blemish to me.
Agree yeah and I'm not saying it's absolutely imperative we don't have duplication. What I'm saying is that there should be a more-or-less canonical path that everything is used from. For example most crates use
std::collections::HashMapand only if other stuff is also imported from thehash_mapmodule might you import it from there. This PR as-is is a mish-mash ofwasmtime::error::Thingvswasmtime::Thing. It's inevitable this will exist to a certain degree, but what I'm asking for is a pass over this to canonicalize onwasmtime::Thingwhere possible.
Overall:
- Due to
wasmtime::*, I'd agreewasmtime::erroris a required module.- I'd like to see a pass to rename
crate::error::Thingat use-sites tocrate::Thingin this PR.- Given the requirement of
wasmtime::errorseems fine to leavewasmtime::error::Contextas-is.- I think it's worth setting expectations that we're doing what we can to smooth this transition but it will, in my opinion, almost surely be a pretty painful transition.
fitzgen updated PR #12231.
fitzgen commented on PR #12231:
Overall:
Due to
wasmtime::*, I'd agreewasmtime::erroris a required module.I'd like to see a pass to rename
crate::error::Thingat use-sites tocrate::Thingin this PR.Given the requirement of
wasmtime::errorseems fine to leavewasmtime::error::Contextas-is.I think it's worth setting expectations that we're doing what we can to smooth this transition but it will, in my opinion, almost surely be a pretty painful transition.
I think we are mostly on the same page.
Regarding the last bullet point, I just don't want to give up on migration ergonomics by-default and only want us to do it deliberately when we have motivation that overrides those ergonomics. There's flex but we should be cognizant when we are making that trade off, not just accepting it as a lost cause from the start.
Latest commit has replaced all
wasmtime::error::Thinguses withwasmtime::Thingother than the following two cases:
wasmtime::error::Ok, which doesn't have a top-level re-export as discussed earlier- in macro-generated code, we are doing UFCS to the
wasmtime::error::Context::contextfunction, and (as also discussed earlier) we don't have a top-level re-export of that function to use, but I also didn't want to switch away from UFCS
fitzgen updated PR #12231.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
s/::error// for non-
Contextthings here
alexcrichton created PR review comment:
s/::error// for non-
Contextthings here
alexcrichton created PR review comment:
s/::error//
alexcrichton created PR review comment:
s/::error//
alexcrichton created PR review comment:
s/::error// for non-
Contextthings here
alexcrichton created PR review comment:
s/::error// (or maybe remove entirely due to the prelude import here)
fitzgen updated PR #12231.
fitzgen has enabled auto merge for PR #12231.
fitzgen merged PR #12231.
Last updated: Jan 09 2026 at 13:15 UTC