Skip to content

Commit 4993524

Browse files
committed
Auto merge of #63814 - malbarbo:wasi-error-kind, r=alexcrichton
Implement decode_error_kind for wasi Based on the implementation for unix targets,
2 parents 9eae1fc + c8838ef commit 4993524

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/libstd/sys/wasi/mod.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,24 @@ pub fn unsupported_err() -> Error {
6464
Error::new(ErrorKind::Other, "operation not supported on wasm yet")
6565
}
6666

67-
pub fn decode_error_kind(_code: i32) -> ErrorKind {
68-
ErrorKind::Other
67+
pub fn decode_error_kind(errno: i32) -> ErrorKind {
68+
match errno as libc::c_int {
69+
libc::ECONNREFUSED => ErrorKind::ConnectionRefused,
70+
libc::ECONNRESET => ErrorKind::ConnectionReset,
71+
libc::EPERM | libc::EACCES => ErrorKind::PermissionDenied,
72+
libc::EPIPE => ErrorKind::BrokenPipe,
73+
libc::ENOTCONN => ErrorKind::NotConnected,
74+
libc::ECONNABORTED => ErrorKind::ConnectionAborted,
75+
libc::EADDRNOTAVAIL => ErrorKind::AddrNotAvailable,
76+
libc::EADDRINUSE => ErrorKind::AddrInUse,
77+
libc::ENOENT => ErrorKind::NotFound,
78+
libc::EINTR => ErrorKind::Interrupted,
79+
libc::EINVAL => ErrorKind::InvalidInput,
80+
libc::ETIMEDOUT => ErrorKind::TimedOut,
81+
libc::EEXIST => ErrorKind::AlreadyExists,
82+
libc::EAGAIN => ErrorKind::WouldBlock,
83+
_ => ErrorKind::Other,
84+
}
6985
}
7086

7187
// This enum is used as the storage for a bunch of types which can't actually

0 commit comments

Comments
 (0)