[wasi-common] Log string representation of WASI errno at the trace level (#760)

* Log str repr of WASI errno at trace level

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`.

* Back port changes to snapshot0

* Fix indentation in logs
This commit is contained in:
Jakub Konka
2020-01-16 21:52:04 +01:00
committed by GitHub
parent b2bfb98f1f
commit e474a9e822
23 changed files with 334 additions and 322 deletions

View File

@@ -1,7 +1,7 @@
#![allow(non_camel_case_types)]
use crate::sys::host_impl;
use crate::sys::hostcalls_impl::fs_helpers::*;
use crate::{fdentry::FdEntry, wasi, Error, Result};
use crate::{error::WasiError, fdentry::FdEntry, wasi, Error, Result};
use std::fs::File;
use std::path::{Component, Path};
@@ -117,10 +117,10 @@ pub(crate) fn path_get(
dir_stack.push(new_dir);
}
Err(e) => {
match e.as_wasi_errno() {
wasi::__WASI_ERRNO_LOOP
| wasi::__WASI_ERRNO_MLINK
| wasi::__WASI_ERRNO_NOTDIR =>
match e.as_wasi_error() {
WasiError::ELOOP
| WasiError::EMLINK
| WasiError::ENOTDIR =>
// Check to see if it was a symlink. Linux indicates
// this with ENOTDIR because of the O_DIRECTORY flag.
{
@@ -179,12 +179,12 @@ pub(crate) fn path_get(
continue;
}
Err(e) => {
if e.as_wasi_errno() != wasi::__WASI_ERRNO_INVAL
&& e.as_wasi_errno() != wasi::__WASI_ERRNO_NOENT
if e.as_wasi_error() != WasiError::EINVAL
&& e.as_wasi_error() != WasiError::ENOENT
// this handles the cases when trying to link to
// a destination that already exists, and the target
// path contains a slash
&& e.as_wasi_errno() != wasi::__WASI_ERRNO_NOTDIR
&& e.as_wasi_error() != WasiError::ENOTDIR
{
return Err(e);
}