Use wiggle "trappable error" to implement wasi-common#5279
Merged
Conversation
Subscribe to Label Actioncc @kubkon DetailsThis issue or pull request has been labeled: "wasi"Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
91d1d20 to
917ea9a
Compare
alexcrichton
approved these changes
Nov 16, 2022
added 2 commits
November 16, 2022 13:28
fun fact! the Send and Recv errors here that just had a `.context` on them were previously not being captured in the downcasting either. They need to be traps, and would have ended up that way by ommission, but you'd never actually know that by reading the code!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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::Errorwith a wiggle-generatedsnapshots::preview_1::types::Errorthroughout 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::Errorhere 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
WasiFileandWasiDirtrait that it was a burden to ensure they only converted errors toanyhow::Errorwhich the corewasi-commonknew how to downcast into anErrno.