-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[wasi-common] Log string representation of WASI errno at the trace level #760
Conversation
FWIW this seems like a good step to me! There does still seem to be what's probably a few too many error types in play, but this seems like a step forward regardless. |
Yes, wasi's strerror, where we get the human-readable strings from the witx, is what was was think we'd eventually want -- though it's more important to get the overall error type situation figured out first. |
I haven't looked at this in detail yet, but at first look, I'm confused about why the winx case is removed from the More broadly, the top-level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change and cleaning up the old conversion functions. Is it needed to make changes to the snapshot? Two more nitpicks in my comments.
crates/wasi-common/src/macros.rs
Outdated
.err() | ||
.unwrap_or(crate::Error::ESUCCESS) | ||
.as_wasi_error(); | ||
log::trace!("\t | errno={}", ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the codebase is not using \t
but
. This is indeed much more readable, but should be consistent across the codebase. But it's ok to deal with it in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, thanks! I'll make sure to update it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; regardless of the merit of tabs, using spaces would allow this to match the indentation level used for similar messages in wasmtime's logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b6a4c4a.
|
||
impl From<WinError> for Error { | ||
fn from(err: WinError) -> Self { | ||
// TODO: implement error mapping between Windows and WASI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO still to be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left it there as a reminder since we don't cover all Windows error codes. Then again, we've got the vast majority of WASI syscalls mapped into Windows, so I'm happy to remove it. The point in favour of leaving it in would be that we still may encounter unmapped Windows-to-WASI error codes when adding new WASI tests in, etc. But I'm happy to go either way with this one :-)
That was the whole point of introducing the top-level Error type: to unify the error handling. Sometimes we need to pass the error returned from some host call (e.g. the underlying |
96417d4
to
720d23d
Compare
I think the confusing thing is that I have a hard time remembering when we convert from host error codes to WASI error codes. With the My bigger question for this PR is why this is removing the |
I think you meant
Now, the reason why this stayed was because I saw more symmetry between
|
Can you give an example of a function where it's particularly useful to return both host errors and WASI errors? I sometimes find myself wanting to think about "when do we resolve host errors into WASI errors?" and with the |
When deciding to use the two-level error hierarchy, I had mostly debugging in mind. Conversion to the errno's is usually lossy, especially for |
I see one good reason to convert to the WASI errno immediately: that |
Hey guys, sorry I didn't look into this in a while but got preoccupied elsewhere. Anyhow, I'm happy to flatten all errors into one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can continue to think about error handling; this PR looks good to more forward to me (modulo the tabs ;-)). Hooray for logging the syscall results!
This commit refactors `Error` enum, and adds logging of the WASI errno string representation at the trace level. Now, when tracing WASI syscalls, we will be greeted with a nicely formatted errno value after each syscall: ``` path_open(...) | *fd=5 | errno=ESUCCESS ``` This commit gets rid of `errno_from_nix`, `errno_from_win` and `errno_from_host` helper fns in favour of direct `From` implementations for the relevant types such as `yanix::Errno` and `winx::winerror::WinError`. `errno_from_host` is replaced by a trait `FromRawOsError`.
5bbb0fd
to
b6a4c4a
Compare
I guess we're good to go with one so I'm gonna go ahead and merge this to unblock for instance #552. |
This commit refactors
Error
enum, and adds logging of the WASI errno string representation at the trace level. Now, when tracing WASI syscalls, we will be greeted with a nicely formatted errno value after each syscall:This commit gets rid of
errno_from_nix
,errno_from_win
anderrno_from_host
helper fns in favour of directFrom
implementations for the relevant types such asyanix::Errno
andwinx::winerror::WinError
.errno_from_host
is replaced by a traitFromRawOsError
.This PR builds on #758, so please don't merge until the other one is merged first.
I'm not entirely sure whether this is the right direction to take, but I hope this PR will be a start. In particular, I left in the
WasiError
enum, but I'm wondering whether it is needed at all. Also, I'm wondering whether we should preserve the error backtrace in the form ofError
enum, or whether outright converting everything to a type that maps one-to-one with__wasi_errno_t
would be sufficient. I guess the debugging process could take a hit then, but would it be major, or could we live with it? Just to clarify, I don't suggest we should answer any of those questions in this PR; I'm simply trying to work out the "best" architecture for error handling inwasi-common
.I like the approach taken in bytecodealliance/wasi crate. @sunfishcode is that the format of
strerror
function you've had in mind?