Stream: wasmtime

Topic: Assumption of anyhow


view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 15:59):

I noticed when executing a component that has an import function, that the bindings use anyhow::Result which the user might not have as a dependency. I was wondering if a fix for this would be welcome or if the bindgen! macro is under so much development that I'd just be getting in the way.

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:02):

ah yeah any anyhow paths should be referenced through wasmtime::component::__internal::anyhow, but it's likely one was missed! PRs more than welcome to fix that of course

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 16:05):

@Alex Crichton unfortunately I think the issue is a bit more complex. The MyComponentImports trait that bindgen! creates needs to be referenced directly by the user. This means the user has to name the return type which is hardcoded to be anyhow::Result<T> where T is the return type of the import function. So I don't think there's really any easy fix - this is sort of by design...

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:05):

oh true, did you have a particular fix in mind?

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 16:07):

The only one that comes to mind is having those functions return Result<T, Box<dyn std::error::Error>> and have the bindgen! macro able to be configured to take some other error type... But that doesn't seem so nice

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:08):

heh yeah anyhow is intentional since it threads all the way into Wasmtime -- do you think we should perhaps publicly reexport anyhow from wasmtime for consumption?

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 16:08):

It seems you're comfortable with having anyhow be a part of the public API, so that would make sense I think

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 16:10):

Perhaps a wasmtime::component::Result?

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:11):

yeah I think that'd be fine

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:11):

we're tied at the hip to anyhow now matter what

view this post on Zulip Alex Crichton (Feb 22 2023 at 16:11):

I think doing wasmtime::Result is also fine

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 16:12):

I can make a PR for that.

view this post on Zulip Ryan Levick (rylev) (Feb 22 2023 at 17:24):

PR is up. https://github.com/bytecodealliance/wasmtime/pull/5853

I added a question on whether this is the right approach or we should be relying on the trappable_error_type option.

As discussed on Zulip, the bindgen! macro assumes the usage of anyhow. This adds a type alias to wasmtime for std::result::Result<T, anyhow::Error> that allows users to use wasmtime::Result where a...

Last updated: Nov 22 2024 at 17:03 UTC