Description
On Windows an io::Error created via from_raw_os_error()
with the Windows system error code ERROR_TIMEOUT
(1460) is not of the kind io::ErrorKind::TimedOut
, but io::ErrorKind::Other
.
This is counter-intuitive considering both (system error code and kind) have (almost) the same symbolic name.
I've tested this with Rust 1.42 on x86_64-pc-windows-gnu, but this behavior is obviously still present in git master. Unless I'm overlooking sth., this should be fairly easy to fix by defining the c::ERROR_TIMEOUT
constant and adding the following after this line:
c::ERROR_TIMEOUT => return ErrorKind::TimedOut,
If you'd like me to, I can prepare a merge request implementing the suggested fix.
I tried this code:
use std::io;
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--500-999-
const ERROR_OPERATION_ABORTED: i32 = 995;
// https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699-
const ERROR_TIMEOUT: i32 = 1460;
fn main() {
assert_eq!(io::Error::from_raw_os_error(ERROR_OPERATION_ABORTED).kind(),
io::ErrorKind::TimedOut);
assert_eq!(io::Error::from_raw_os_error(ERROR_TIMEOUT).kind(),
io::ErrorKind::TimedOut);
}
I expected to see this happen: Assertion passes because (should be):
io::Error::from_raw_os_error(ERROR_TIMEOUT).kind() == io::ErrorKind::TimedOut`
Instead, this happened: Assertion fails because:
io::Error::from_raw_os_error(ERROR_TIMEOUT).kind() == io::ErrorKind::Other`
Meta
rustc --version --verbose
:
rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-pc-windows-gnu
release: 1.42.0
LLVM version: 9.0
Backtrace
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Other`,
right: `TimedOut`', src\main.rs:9:5
stack backtrace:
0: backtrace::backtrace::dbghelp::trace
at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/dbghelp.rs:88
1: backtrace::backtrace::trace_unsynchronized
at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.40\src\backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src\libstd\sys_common/backtrace.rs:77
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src\libstd\sys_common/backtrace.rs:59
4: core::fmt::write
at src\libcore\fmt/mod.rs:1052
5: std::io::Write::write_fmt
at src\libstd\io/mod.rs:1426
6: std::sys_common::backtrace::_print
at src\libstd\sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src\libstd\sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src\libstd/panicking.rs:204
9: std::panicking::default_hook
at src\libstd/panicking.rs:224
10: std::panicking::rust_panic_with_hook
at src\libstd/panicking.rs:472
11: rust_begin_unwind
at src\libstd/panicking.rs:380
12: std::panicking::begin_panic_fmt
at src\libstd/panicking.rs:334
13: rust_test::main
at src/main.rs:9
14: std::rt::lang_start::{{closure}}
at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd/rt.rs:67
15: std::rt::lang_start_internal::{{closure}}
at src\libstd/rt.rs:52
16: std::panicking::try::do_call
at src\libstd/panicking.rs:305
17: __rust_maybe_catch_panic
at src\libpanic_unwind/lib.rs:86
18: std::panicking::try
at src\libstd/panicking.rs:281
19: std::panic::catch_unwind
at src\libstd/panic.rs:394
20: std::rt::lang_start_internal
at src\libstd/rt.rs:51
21: std::rt::lang_start
at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447\src\libstd/rt.rs:67
22: main
23: _tmainCRTStartup
24: mainCRTStartup
25: unit_addrs_search
26: unit_addrs_search
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\rust-test.exe` (exit code: 101)