Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wiggle "trappable error" to implement wasi-common #5279

Merged
merged 7 commits into from
Nov 17, 2022

Conversation

pchickey
Copy link
Contributor

@pchickey pchickey commented Nov 16, 2022

Based on #5276

This PR replaces the use of anyhow::Error with a wiggle-generated snapshots::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 an anyhow::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 and WasiDir trait that it was a burden to ensure they only converted errors to anyhow::Error which the core wasi-common knew how to downcast into an Errno.

@github-actions github-actions bot added the wasi Issues pertaining to WASI label Nov 16, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @kubkon

This issue or pull request has been labeled: "wasi"

Thus the following users have been cc'd because of the following labels:

  • kubkon: wasi

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@pchickey pchickey marked this pull request as ready for review November 16, 2022 01:43
@pchickey pchickey force-pushed the pch/wasi_common_trappable_error branch from 91d1d20 to 917ea9a Compare November 16, 2022 17:29
Pat Hickey 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!
@pchickey pchickey merged commit 56daa8a into main Nov 17, 2022
@pchickey pchickey deleted the pch/wasi_common_trappable_error branch November 17, 2022 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants