Skip to content

Commit 9d10637

Browse files
committed
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.
1 parent 0fa1865 commit 9d10637

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: lightning-block-sync/src/http.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,9 @@ pub(crate) mod client_tests {
636636
#[test]
637637
fn connect_to_unresolvable_host() {
638638
match HttpClient::connect(("example.invalid", 80)) {
639-
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::Other),
639+
Err(e) => {
640+
assert!(e.to_string().contains("failed to lookup address information"), "{:?}", e);
641+
},
640642
Ok(_) => panic!("Expected error"),
641643
}
642644
}

Diff for: lightning-persister/src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod tests {
135135
// Create the channel data file and make it a directory.
136136
fs::create_dir_all(get_full_filepath(path.clone(), filename.to_string())).unwrap();
137137
match write_to_file(path.clone(), filename.to_string(), &test_writeable) {
138-
Err(e) => assert_eq!(e.kind(), io::ErrorKind::Other),
138+
Err(e) => assert_eq!(e.raw_os_error(), Some(libc::EISDIR)),
139139
_ => panic!("Unexpected Ok(())")
140140
}
141141
fs::remove_dir_all(path).unwrap();
@@ -178,7 +178,7 @@ mod tests {
178178
match write_to_file(path, filename, &test_writeable) {
179179
Err(e) => {
180180
#[cfg(not(target_os = "windows"))]
181-
assert_eq!(e.kind(), io::ErrorKind::Other);
181+
assert_eq!(e.raw_os_error(), Some(libc::EISDIR));
182182
#[cfg(target_os = "windows")]
183183
assert_eq!(e.kind(), io::ErrorKind::PermissionDenied);
184184
}

0 commit comments

Comments
 (0)