bytecodealliance / bytecodealliance/wasmtime

Expose `wasmtime_runtime::InstantiationError` as a stable wasmtime API

Open
#3,928 2 comments 0 reactions 0 assignees View on GitHub
wasmtime wasmtime:api
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 19h
Merged PRs (30d)
121

Description

#### Feature

Presently, the `instantiate` family of functions (`Linker::instantiate`, `InstancePre::instantiate`, their _async cousins etc) error with an `anyhow::Error`. To inspect those errors, we can try downcasting to `wasmtime_runtime::InstantiationError`.

#### Benefit

Users who need to inspect those errors need to keep their deps of wasmtime and wasmtime_runtime in sync. wasmtime_runtime's API is not designed for stable use. Stabilizing this error API gets rid of a possible runtime dep for users.

The `InstantiationError::Limit` variant is used when a wasmtime pooling allocator is out of instances. This is the only way that wasmtime crate users can observe this condition. There should be a stable way to observe this.

The `InstantiationError::Trap` variant contains a `wasmtime_runtime::Trap`, which is different from a `wasmtime::Trap` in ways that aren't useful to wasmtime users, and can be confusing.

#### Implementation

I think it makes sense for the instantiate family of functions to still error with an `anyhow::Error`, but wasmtime should export types to try downcasting that error to.

Wasmtime should not re-export `wasmtime_runtime::InstantiationError` because it exposes the wrong sort of `Trap`. Instead it should map the variants to types which are in the public API.

```
pub enum InstantiationError {
Resource(anyhow::Error),
Link(LinkError),
Trap(Trap),
Limit(u32),
}
```
* Resource variant: just return the anyhow::Error here.
* Link variant: re-export `wasmtime_runtime::LinkError` for downcasting to that variant, since this is just a string wrapper.
* Trap variant: map the contents to a `wasmtime::Trap`.
* Limit variant: Wasmtime could define a new public type `PoolingAllocatorLimit` and `impl Error` on it, and map the `InstantiationError::Limit` variant to that type.

#### Alternatives

There are probably other good ideas I haven't thought of here! I am very open to suggestions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.