Skip to content

Commit a9bd71e

Browse files
authored
Issue a better error message if the target is unsupported. (#110)
Following an idea from in #76, add a sys.rs file, which only gets used if the target isn't recognized, and use `compile_error` to give a meaningful error message instead of cryptically failing on the compiler being unable to open sys.rs. For example, using --target=wasm32-unknown-unknown now gets this error: ```console $ cargo check --target=wasm32-unknown-unknown Checking errno v0.3.11 error: The target OS is "unknown" or "none", so it's unsupported by the errno crate. --> src/sys.rs:8:1 | 8 | compile_error!("The target OS is \"unknown\" or \"none\", so it's unsupported by the errno crate."); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: could not compile `errno` (lib) due to 1 previous error ```
1 parent afcb78b commit a9bd71e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/sys.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! A default sys.rs for unrecognized targets.
2+
//!
3+
//! If lib.rs doesn't recognize the target, it defaults to using this file,
4+
//! which issues an explanatory compile error.
5+
6+
// If there is no OS, there's no `errno` or equivalent defined.
7+
#[cfg(any(target_os = "unknown", target_os = "none"))]
8+
compile_error!("The target OS is \"unknown\" or \"none\", so it's unsupported by the errno crate.");
9+
10+
// If there is an OS, support may be added.
11+
#[cfg(not(any(target_os = "unknown", target_os = "none")))]
12+
compile_error!("The target OS is not yet supported in the errno crate.");
13+
14+
// The following define the functions of the normal implementations
15+
// so that the user doesn't see uninteresting errors after the
16+
// errors above.
17+
18+
use crate::Errno;
19+
20+
pub fn with_description<F, T>(_err: Errno, _callback: F) -> T
21+
where
22+
F: FnOnce(Result<&str, Errno>) -> T,
23+
{
24+
unreachable!()
25+
}
26+
27+
pub const STRERROR_NAME: &str = "";
28+
29+
pub fn errno() -> Errno {
30+
unreachable!()
31+
}
32+
33+
pub fn set_errno(_: Errno) {
34+
unreachable!()
35+
}

0 commit comments

Comments
 (0)