]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/solid/error.rs
Auto merge of #103459 - ChrisDenton:propagate-nulls, r=thomcc
[rust.git] / library / std / src / sys / solid / error.rs
1 use super::{abi, itron, net};
2 use crate::io::ErrorKind;
3
4 pub use self::itron::error::{expect_success, ItronError as SolidError};
5
6 /// Describe the specified SOLID error code. Returns `None` if it's an
7 /// undefined error code.
8 ///
9 /// The SOLID error codes are a superset of μITRON error codes.
10 pub fn error_name(er: abi::ER) -> Option<&'static str> {
11     match er {
12         // Success
13         er if er >= 0 => None,
14         er if er < abi::sockets::SOLID_NET_ERR_BASE => net::error_name(er),
15
16         abi::SOLID_ERR_NOTFOUND => Some("not found"),
17         abi::SOLID_ERR_NOTSUPPORTED => Some("not supported"),
18         abi::SOLID_ERR_EBADF => Some("bad flags"),
19         abi::SOLID_ERR_INVALIDCONTENT => Some("invalid content"),
20         abi::SOLID_ERR_NOTUSED => Some("not used"),
21         abi::SOLID_ERR_ALREADYUSED => Some("already used"),
22         abi::SOLID_ERR_OUTOFBOUND => Some("out of bounds"),
23         abi::SOLID_ERR_BADSEQUENCE => Some("bad sequence"),
24         abi::SOLID_ERR_UNKNOWNDEVICE => Some("unknown device"),
25         abi::SOLID_ERR_BUSY => Some("busy"),
26         abi::SOLID_ERR_TIMEOUT => Some("operation timed out"),
27         abi::SOLID_ERR_INVALIDACCESS => Some("invalid access"),
28         abi::SOLID_ERR_NOTREADY => Some("not ready"),
29
30         _ => itron::error::error_name(er),
31     }
32 }
33
34 pub fn decode_error_kind(er: abi::ER) -> ErrorKind {
35     match er {
36         // Success
37         er if er >= 0 => ErrorKind::Uncategorized,
38         er if er < abi::sockets::SOLID_NET_ERR_BASE => net::decode_error_kind(er),
39
40         abi::SOLID_ERR_NOTFOUND => ErrorKind::NotFound,
41         abi::SOLID_ERR_NOTSUPPORTED => ErrorKind::Unsupported,
42         abi::SOLID_ERR_EBADF => ErrorKind::InvalidInput,
43         abi::SOLID_ERR_INVALIDCONTENT => ErrorKind::InvalidData,
44         // abi::SOLID_ERR_NOTUSED
45         // abi::SOLID_ERR_ALREADYUSED
46         abi::SOLID_ERR_OUTOFBOUND => ErrorKind::InvalidInput,
47         // abi::SOLID_ERR_BADSEQUENCE
48         abi::SOLID_ERR_UNKNOWNDEVICE => ErrorKind::NotFound,
49         // abi::SOLID_ERR_BUSY
50         abi::SOLID_ERR_TIMEOUT => ErrorKind::TimedOut,
51         // abi::SOLID_ERR_INVALIDACCESS
52         // abi::SOLID_ERR_NOTREADY
53         _ => itron::error::decode_error_kind(er),
54     }
55 }