Skip to content

wasm-wave: return an error instead of panicking on unsupported values - #2778

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
jrandolf:wave-writer-unsupported-error
Oct 21, 2026
Merged

alexcrichton merged 1 commit into
bytecodealliance:mainfrom
jrandolf:wave-writer-unsupported-error

Conversation

@jrandolf

Copy link
Copy Markdown
Contributor

Writing a value whose kind is WasmTypeKind::Unsupported panicked in the writer, so e.g. Wasmtime's --invoke crashes on functions returning a component model map (bytecodealliance/wasmtime#14811). This returns a new WriterError::UnsupportedType instead (WriterError is already #[non_exhaustive]). DisplayValue still maps it to fmt::Error, so its docs now point at to_string for callers that want the error.

Actual map support is tracked in #2777.

`Writer::write_value` panicked when it encountered a value whose kind is
`WasmTypeKind::Unsupported`, which is how embedders such as Wasmtime
represent component-model values that WAVE can't encode yet (e.g.
`map<K, V>`, resources, streams, and futures). As a result
`wasm_wave::to_string` could panic despite returning a `Result`.

Add a `WriterError::UnsupportedType` variant and return it instead.
`WriterError` is already `#[non_exhaustive]`, so this is not a breaking
change. `DisplayValue` maps writer errors to `fmt::Error`, so formatting
an unsupported value through it now returns an error as well.

See bytecodealliance/wasmtime#14811.
@jrandolf
jrandolf marked this pull request as ready for review October 19, 2026 19:21
@jrandolf
jrandolf requested a review from a team as a code owner October 19, 2026 19:21
@jrandolf
jrandolf requested review from dicej and removed request for a team October 19, 2026 19:21
@alexcrichton
alexcrichton added this pull request to the merge queue Oct 21, 2026
Merged via the queue into bytecodealliance:main with commit c3fa935 Oct 21, 2026
37 checks passed
jrandolf added a commit to jrandolf/wasmtime that referenced this pull request Oct 21, 2026
WAVE can't represent some component values, such as `map`s, resources,
futures, streams, and error contexts. wasm-wave's `DisplayValue`
returns a `fmt::Error` for them, so formatting one panics, which made
`wasmtime run --invoke` panic when the invoked function returned a
`map`.

`--invoke` now prints results through `Val::to_wave`, which returns an
error for these values, so it reports the error and exits with a
failure instead. The error messages built in `ensure_type_val` no
longer format values through `DisplayValue` either.

This relies on bytecodealliance/wasm-tools#2778, which makes
wasm-wave's writer return an error instead of panicking on these
values. It's a stopgap for bytecodealliance#14811; rendering `map`s needs support in
wasm-wave.
jrandolf added a commit to jrandolf/wasmtime that referenced this pull request Oct 21, 2026
Point the wasm-tools crates at the `wave-writer-unsupported-error` branch
of jrandolf/wasm-tools, which is bytecodealliance/wasm-tools#2778 as
merged but without the later changes on wasm-tools' main. Every wasm-tools
crate is patched, not just wasm-wave, because within wasm-tools the crates
depend on each other directly.

Drop this commit once a wasm-tools release with that change is out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants