diff --git a/crates/nu-command/tests/commands/network/http/delete.rs b/crates/nu-command/tests/commands/network/http/delete.rs index 2e2624122e..ac79a4fe62 100644 --- a/crates/nu-command/tests/commands/network/http/delete.rs +++ b/crates/nu-command/tests/commands/network/http/delete.rs @@ -131,14 +131,21 @@ fn http_delete_timeout() { let _mock = server .mock("DELETE", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( - format!("http delete --max-time 500ms {url}", url = server.url()).as_str() + format!("http delete --max-time 100ms {url}", url = server.url()).as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-command/tests/commands/network/http/get.rs b/crates/nu-command/tests/commands/network/http/get.rs index e75536abb4..87b6b93388 100644 --- a/crates/nu-command/tests/commands/network/http/get.rs +++ b/crates/nu-command/tests/commands/network/http/get.rs @@ -325,14 +325,21 @@ fn http_get_timeout() { let _mock = server .mock("GET", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( - format!("http get --max-time 500ms {url}", url = server.url()).as_str() + format!("http get --max-time 100ms {url}", url = server.url()).as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-command/tests/commands/network/http/options.rs b/crates/nu-command/tests/commands/network/http/options.rs index 82dcf33a5a..b1478b4ecc 100644 --- a/crates/nu-command/tests/commands/network/http/options.rs +++ b/crates/nu-command/tests/commands/network/http/options.rs @@ -50,14 +50,21 @@ fn http_options_timeout() { let _mock = server .mock("OPTIONS", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( - format!("http options --max-time 500ms {url}", url = server.url()).as_str() + format!("http options --max-time 100ms {url}", url = server.url()).as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-command/tests/commands/network/http/patch.rs b/crates/nu-command/tests/commands/network/http/patch.rs index 79e6a63096..90788f6769 100644 --- a/crates/nu-command/tests/commands/network/http/patch.rs +++ b/crates/nu-command/tests/commands/network/http/patch.rs @@ -171,18 +171,25 @@ fn http_patch_timeout() { let _mock = server .mock("PATCH", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( format!( - "http patch --max-time 500ms {url} patchbody", + "http patch --max-time 100ms {url} patchbody", url = server.url() ) .as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-command/tests/commands/network/http/post.rs b/crates/nu-command/tests/commands/network/http/post.rs index 9d327bf167..2b238573fa 100644 --- a/crates/nu-command/tests/commands/network/http/post.rs +++ b/crates/nu-command/tests/commands/network/http/post.rs @@ -285,18 +285,25 @@ fn http_post_timeout() { let _mock = server .mock("POST", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( format!( - "http post --max-time 500ms {url} postbody", + "http post --max-time 100ms {url} postbody", url = server.url() ) .as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-command/tests/commands/network/http/put.rs b/crates/nu-command/tests/commands/network/http/put.rs index 3405c19bbf..41a4bf7848 100644 --- a/crates/nu-command/tests/commands/network/http/put.rs +++ b/crates/nu-command/tests/commands/network/http/put.rs @@ -171,18 +171,25 @@ fn http_put_timeout() { let _mock = server .mock("PUT", "/") .with_chunked_body(|w| { - thread::sleep(Duration::from_secs(1)); + thread::sleep(Duration::from_secs(10)); w.write_all(b"Delayed response!") }) .create(); let actual = nu!(pipeline( format!( - "http put --max-time 500ms {url} putbody", + "http put --max-time 100ms {url} putbody", url = server.url() ) .as_str() )); - assert!(&actual.err.contains("nu::shell::io_error")); + assert!(&actual.err.contains("nu::shell::network_failure")); + + #[cfg(not(target_os = "windows"))] + assert!(&actual.err.contains("timed out reading response")); + #[cfg(target_os = "windows")] + assert!(&actual + .err + .contains("did not properly respond after a period of time")); } diff --git a/crates/nu-protocol/src/errors/shell_error.rs b/crates/nu-protocol/src/errors/shell_error.rs index f187dde807..f9ccc73c54 100644 --- a/crates/nu-protocol/src/errors/shell_error.rs +++ b/crates/nu-protocol/src/errors/shell_error.rs @@ -1544,8 +1544,8 @@ impl From<io::Error> for ShellError { impl From<Spanned<io::Error>> for ShellError { fn from(error: Spanned<io::Error>) -> Self { let Spanned { item: error, span } = error; - if error.kind() == io::ErrorKind::Other { - match error.into_inner() { + match error.kind() { + io::ErrorKind::Other => match error.into_inner() { Some(err) => match err.downcast() { Ok(err) => *err, Err(err) => Self::IOErrorSpanned { @@ -1557,12 +1557,15 @@ impl From<Spanned<io::Error>> for ShellError { msg: "unknown error".into(), span, }, - } - } else { - Self::IOErrorSpanned { + }, + io::ErrorKind::TimedOut => Self::NetworkFailure { msg: error.to_string(), span, - } + }, + _ => Self::IOErrorSpanned { + msg: error.to_string(), + span, + }, } } }