Polyfill ToWasmtimeResult and add eventually-necessary call sites#12308
Polyfill ToWasmtimeResult and add eventually-necessary call sites#12308fitzgen merged 5 commits intobytecodealliance:mainfrom
ToWasmtimeResult and add eventually-necessary call sites#12308Conversation
This commit polyfills `wasmtime_internal_error::ToWasmtimeResult` in `wasmtime_environ`, adds the cargo feature plumbing that will eventually connect to the `"wasmtime_internal_error/anyhow"` cargo feature but for now just configures this polyfill, and adds uses of the polyfill at all the sites that will be necessary once we swap out `anyhow` for `wasmtime_internal_error`. Currently, the polyfill is just an identity function, because `wasmtime::Result`/`wasmtime_environ::error::Result` is just another name for `anyhow::Result`. Once we do move away from `anyhow`, however, that will no longer be the case, and these uses will do the necessary conversion. My goal with landing this as an incremental commit is to make it so that the actual commit that does the error crate swap out can be as close to _just_ the `Cargo.toml` dependency change, without any other code changes as much as possible. This, in turn, means that swap out should be super easy to revert, if necessary.
|
Personally I'd like to see this trait used as an absolute last resort "quick hack before we figure out what's best to do instead" ideally. What would you think about, instead of using this trait internally, instead propagating the usage of Additionally, looking forward a bit, one thing I'm worried about is |
Subscribe to Label Actioncc @fitzgen DetailsThis issue or pull request has been labeled: "wasmtime:api", "wizer"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
This trait is used as an absolute last resort, and not as a quick hack, already in this PR as it is today:
This is not a quick hack. This is only and exactly the places where we must insert the conversions.
This would result in a much more confusing situation where sometimes we are using
Makes sense to me, but also probably something that doesn't need to happen in this PR, I don't think? If you feel strongly that it should be part of this PR, I can add it here though. |
|
Sorry yeah "quick hack" is not the right term for this, I was trying to emulate a use case of using I think you're right as well that, in this workspace, trying to sometimes use Personally though I'm still not a fan of this trait. Idiomatically in Rust everyone expects
I think it would be reasonable to update these libraries to have a more dedicated error-type-per-library which does indeed implement the Question for you though, the other instance in this PR is the updates to the
Agreed yeah, the If you're ok with it I'd prefer to block landing the actual switchover until this PR is implemented, but I would hope that this PR would be pretty easy to do. |
Yes, I would agree. We really shouldn't be doing that as much as possible. Also somewhat Rust-the-language's fault for not allowing some kind of very basic specialization or something to enable both of the following impls to co-exist: impl<E: core::error::Error> From<E> for wasmtime::Error { ... }
impl From<anyhow::Error> for wasmtime::Error { ... }
I wasn't totally sure what to do about cranelift code using I am not sure these were the right decisions. Maybe better to
Any opinions on this? Or we can just leave the cut as-is. Its a bit ambiguous to me.
Sounds good to me. |
|
I'd say switch cranelift fuzzing over to |
… code" This reverts commit b33696e.
Subscribe to Label Actioncc @fitzgen DetailsThis issue or pull request has been labeled: "fuzzing"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
This commit polyfills
wasmtime_internal_error::ToWasmtimeResultinwasmtime_environ, adds the cargo feature plumbing that will eventually connect to the"wasmtime_internal_error/anyhow"cargo feature but for now just configures this polyfill, and adds uses of the polyfill at all the sites that will be necessary once we swap outanyhowforwasmtime_internal_error. Currently, the polyfill is just an identity function, becausewasmtime::Result/wasmtime_environ::error::Resultis just another name foranyhow::Result. Once we do move away fromanyhow, however, that will no longer be the case, and these uses will do the necessary conversion.My goal with landing this as an incremental commit is to make it so that the actual commit that does the error crate swap out can be as close to just the
Cargo.tomldependency change, without any other code changes as much as possible. This, in turn, means that swap out should be super easy to revert, if necessary.