Skip to content

Commit

Permalink
Use io_error_more on WASI
Browse files Browse the repository at this point in the history
  • Loading branch information
ShE3py committed Aug 10, 2023
1 parent 9fa6bdd commit 87ecf7f
Showing 1 changed file with 71 additions and 13 deletions.
84 changes: 71 additions & 13 deletions library/std/src/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,82 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
}

match errno {
e if e == wasi::ERRNO_2BIG.raw().into() => ArgumentListTooLong,
e if e == wasi::ERRNO_ACCES.raw().into() => PermissionDenied,
e if e == wasi::ERRNO_ADDRINUSE.raw().into() => AddrInUse,
e if e == wasi::ERRNO_ADDRNOTAVAIL.raw().into() => AddrNotAvailable,
// wasi::ERRNO_AFNOSUPPORT.raw().into() => "address family not supported",
e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock,
// wasi::ERRNO_ALREADY.raw().into() => "connection already in progress",
// wasi::ERRNO_BADF.raw().into() => "bad file descriptor",
// wasi::ERRNO_BADMSG.raw().into() => "bad message",
e if e == wasi::ERRNO_BUSY.raw().into() => ResourceBusy,
// wasi::ERRNO_CANCELED.raw().into() => "operation canceled",
// wasi::ERRNO_CHILD.raw().into() => "no child processes",
e if e == wasi::ERRNO_CONNABORTED.raw().into() => ConnectionAborted,
e if e == wasi::ERRNO_CONNREFUSED.raw().into() => ConnectionRefused,
e if e == wasi::ERRNO_CONNRESET.raw().into() => ConnectionReset,
e if e == wasi::ERRNO_PERM.raw().into() || e == wasi::ERRNO_ACCES.raw().into() => {
PermissionDenied
}
e if e == wasi::ERRNO_PIPE.raw().into() => BrokenPipe,
e if e == wasi::ERRNO_NOTCONN.raw().into() => NotConnected,
e if e == wasi::ERRNO_CONNABORTED.raw().into() => ConnectionAborted,
e if e == wasi::ERRNO_ADDRNOTAVAIL.raw().into() => AddrNotAvailable,
e if e == wasi::ERRNO_ADDRINUSE.raw().into() => AddrInUse,
e if e == wasi::ERRNO_NOENT.raw().into() => NotFound,
e if e == wasi::ERRNO_DEADLK.raw().into() => Deadlock,
// wasi::ERRNO_DESTADDRREQ.raw().into() => "destination address required",
// wasi::ERRNO_DOM.raw().into() => "mathematics argument out of domain of function",
// wasi::ERRNO_DQUOT.raw().into() => "reserved",
e if e == wasi::ERRNO_EXIST.raw().into() => AlreadyExists,
// wasi::ERRNO_FAULT.raw().into() => "bad address",
e if e == wasi::ERRNO_FBIG.raw().into() => FileTooLarge,
e if e == wasi::ERRNO_HOSTUNREACH.raw().into() => HostUnreachable,
// wasi::ERRNO_IDRM.raw().into() => "identifier removed",
// wasi::ERRNO_ILSEQ.raw().into() => "illegal byte sequence",
// wasi::ERRNO_INPROGRESS.raw().into() => "operation in progress",
e if e == wasi::ERRNO_INTR.raw().into() => Interrupted,
e if e == wasi::ERRNO_INVAL.raw().into() => InvalidInput,
e if e == wasi::ERRNO_TIMEDOUT.raw().into() => TimedOut,
e if e == wasi::ERRNO_EXIST.raw().into() => AlreadyExists,
e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock,
e if e == wasi::ERRNO_NOSYS.raw().into() => Unsupported,
e if e == wasi::ERRNO_IO.raw().into() => Uncategorized,
// wasi::ERRNO_ISCONN.raw().into() => "socket is connected",
e if e == wasi::ERRNO_ISDIR.raw().into() => IsADirectory,
e if e == wasi::ERRNO_LOOP.raw().into() => FilesystemLoop,
// wasi::ERRNO_MFILE.raw().into() => "file descriptor value too large",
e if e == wasi::ERRNO_MLINK.raw().into() => TooManyLinks,
// wasi::ERRNO_MSGSIZE.raw().into() => "message too large",
// wasi::ERRNO_MULTIHOP.raw().into() => "reserved",
e if e == wasi::ERRNO_NAMETOOLONG.raw().into() => InvalidFilename,
e if e == wasi::ERRNO_NETDOWN.raw().into() => NetworkDown,
// wasi::ERRNO_NETRESET.raw().into() => "connection aborted by network",
e if e == wasi::ERRNO_NETUNREACH.raw().into() => NetworkUnreachable,
// wasi::ERRNO_NFILE.raw().into() => "too many files open in system",
// wasi::ERRNO_NOBUFS.raw().into() => "no buffer space available",
e if e == wasi::ERRNO_NODEV.raw().into() => NotFound,
e if e == wasi::ERRNO_NOENT.raw().into() => NotFound,
e if e == wasi::ERRNO_NOEXEC.raw().into() => InvalidData,
// wasi::ERRNO_NOLCK.raw().into() => "no locks available",
// wasi::ERRNO_NOLINK.raw().into() => "reserved",
e if e == wasi::ERRNO_NOMEM.raw().into() => OutOfMemory,
// wasi::ERRNO_NOMSG.raw().into() => "no message of the desired type",
// wasi::ERRNO_NOPROTOOPT.raw().into() => "protocol not available",
e if e == wasi::ERRNO_NOSPC.raw().into() => StorageFull,
e if e == wasi::ERRNO_NOSYS.raw().into() => Unsupported,
e if e == wasi::ERRNO_NOTCONN.raw().into() => NotConnected,
e if e == wasi::ERRNO_NOTDIR.raw().into() => NotADirectory,
e if e == wasi::ERRNO_NOTEMPTY.raw().into() => DirectoryNotEmpty,
// wasi::ERRNO_NOTRECOVERABLE.raw().into() => "state not recoverable",
e if e == wasi::ERRNO_NOTSOCK.raw().into() => InvalidInput,
e if e == wasi::ERRNO_NOTSUP.raw().into() => Unsupported,
// wasi::ERRNO_NOTTY.raw().into() => "inappropriate I/O control operation",
e if e == wasi::ERRNO_NXIO.raw().into() => NotFound,
// wasi::ERRNO_OVERFLOW.raw().into() => "value too large to be stored in data type",
// wasi::ERRNO_OWNERDEAD.raw().into() => "previous owner died",
e if e == wasi::ERRNO_PERM.raw().into() => PermissionDenied,
e if e == wasi::ERRNO_PIPE.raw().into() => BrokenPipe,
// wasi::ERRNO_PROTO.raw().into() => "protocol error",
e if e == wasi::ERRNO_PROTONOSUPPORT.raw().into() => Unsupported,
e if e == wasi::ERRNO_PROTOTYPE.raw().into() => InvalidInput,
// wasi::ERRNO_RANGE.raw().into() => "result too large",
e if e == wasi::ERRNO_ROFS.raw().into() => ReadOnlyFilesystem,
// wasi::ERRNO_SPIPE.raw().into() => "invalid seek",
e if e == wasi::ERRNO_SRCH.raw().into() => NotFound,
// wasi::ERRNO_STALE.raw().into() => "reserved",
e if e == wasi::ERRNO_TIMEDOUT.raw().into() => TimedOut,
e if e == wasi::ERRNO_TXTBSY.raw().into() => ResourceBusy,
e if e == wasi::ERRNO_XDEV.raw().into() => CrossesDevices,
e if e == wasi::ERRNO_NOTCAPABLE.raw().into() => PermissionDenied,
_ => Uncategorized,
}
}
Expand Down

0 comments on commit 87ecf7f

Please sign in to comment.