From: Matt Corallo Date: Mon, 2 Aug 2021 15:04:40 +0000 (+0000) Subject: Check IO errors in test using `raw_os_error()` instead of `kind()` X-Git-Tag: v0.0.100~13^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=84909447e9efb9737f6d7bfaecd6f0d863464625;p=rust-lightning Check IO errors in test using `raw_os_error()` instead of `kind()` std::io::ErrorKind is a `#[non_exhaustive]` enum as more specific error types are to be added in the future. It was unclear in the docs until very recently, however, that this is to be done by re-defining `ErrorKind::Other` errors to new enum variants. Thus, our tests which check explicitly for `ErrorKind::Other` as a result of trying to access a directory as a file were incorrect. Sadly, these generated no meaningful feedback from rustc at all, except that they're suddenly failing in rustc beta! After some back-and-forth, it seems rustc is moving forward breaking existing code in future versions, so we move to the "correct" check here, which is to check the raw IO error. See rust-lang/rust#86442 and rust-lang/rust#85746 for more info. --- diff --git a/lightning-block-sync/src/http.rs b/lightning-block-sync/src/http.rs index 89054a23f..0721babfd 100644 --- a/lightning-block-sync/src/http.rs +++ b/lightning-block-sync/src/http.rs @@ -636,7 +636,10 @@ pub(crate) mod client_tests { #[test] fn connect_to_unresolvable_host() { match HttpClient::connect(("example.invalid", 80)) { - Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::Other), + Err(e) => { + assert!(e.to_string().contains("failed to lookup address information") || + e.to_string().contains("No such host"), "{:?}", e); + }, Ok(_) => panic!("Expected error"), } } diff --git a/lightning-persister/src/util.rs b/lightning-persister/src/util.rs index 1825980ad..73b28985b 100644 --- a/lightning-persister/src/util.rs +++ b/lightning-persister/src/util.rs @@ -135,7 +135,7 @@ mod tests { // Create the channel data file and make it a directory. fs::create_dir_all(get_full_filepath(path.clone(), filename.to_string())).unwrap(); match write_to_file(path.clone(), filename.to_string(), &test_writeable) { - Err(e) => assert_eq!(e.kind(), io::ErrorKind::Other), + Err(e) => assert_eq!(e.raw_os_error(), Some(libc::EISDIR)), _ => panic!("Unexpected Ok(())") } fs::remove_dir_all(path).unwrap(); @@ -178,7 +178,7 @@ mod tests { match write_to_file(path, filename, &test_writeable) { Err(e) => { #[cfg(not(target_os = "windows"))] - assert_eq!(e.kind(), io::ErrorKind::Other); + assert_eq!(e.raw_os_error(), Some(libc::EISDIR)); #[cfg(target_os = "windows")] assert_eq!(e.kind(), io::ErrorKind::PermissionDenied); }