Use wiggle "trappable error" to implement wasi-common #5279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on #5276
This PR replaces the use of
anyhow::Error
with a wiggle-generatedsnapshots::preview_1::types::Error
throughout the wasi-common (and child) crates.This change was ultimately for better type safety. The old conversion code https://github.com/bytecodealliance/wasmtime/pull/5279/files#diff-40a165c1f24fb0428d93215436730254f0379f22e816a70e0e29a44ba99c8be4L45-L66 from anyhow::Error to the concrete Errno type missed a downcast of
cap_rand::Error
, which gets convereted to ananyhow::Error
here https://github.com/bytecodealliance/wasmtime/blob/91d1d20cb628bf7875199fe5f4a4b232933bdbcb/crates/wasi-common/src/snapshots/preview_1.rs#LL1036-L1036C5 since 2019, and I probably never would have discovered it if I hadn't tried refactoring the error representation to be more typesafe.We're preparing wasi-common for the coming component-based preview 2, which will have (among other improvements) a wider range of errno types. With the increase in complexity, I was more worried about correctness than ergonomics. I also got reports from other crate authors implementing the
WasiFile
andWasiDir
trait that it was a burden to ensure they only converted errors toanyhow::Error
which the corewasi-common
knew how to downcast into anErrno
.