diff --git a/.cspell.yml b/.cspell.yml index 83c29f0af..813349383 100644 --- a/.cspell.yml +++ b/.cspell.yml @@ -1,4 +1,5 @@ version: "0.2" words: - actix + - httparse - rustup diff --git a/actix-http/examples/streaming-error.rs b/actix-http/examples/streaming-error.rs index 39f214fa1..8d494b64e 100644 --- a/actix-http/examples/streaming-error.rs +++ b/actix-http/examples/streaming-error.rs @@ -31,7 +31,7 @@ async fn main() -> io::Result<()> { actix_rt::time::sleep(Duration::from_secs(1)).await; - yield Err(io::Error::new(io::ErrorKind::Other, "abc")); + yield Err(io::Error::other("abc")); }))) }) .tcp() diff --git a/actix-http/src/body/utils.rs b/actix-http/src/body/utils.rs index b8bfa96cf..a234222aa 100644 --- a/actix-http/src/body/utils.rs +++ b/actix-http/src/body/utils.rs @@ -190,7 +190,7 @@ mod tests { #[actix_rt::test] async fn to_body_limit_error() { - let err_stream = stream::once(async { Err(io::Error::new(io::ErrorKind::Other, "")) }); + let err_stream = stream::once(async { Err(io::Error::other("")) }); let body = SizedStream::new(8, err_stream); // not too big, but propagates error from body stream assert!(to_bytes_limited(body, 10).await.unwrap().is_err()); diff --git a/actix-http/src/encoding/decoder.rs b/actix-http/src/encoding/decoder.rs index cda534d60..1247c0a55 100644 --- a/actix-http/src/encoding/decoder.rs +++ b/actix-http/src/encoding/decoder.rs @@ -100,10 +100,7 @@ where loop { if let Some(ref mut fut) = this.fut { let (chunk, decoder) = ready!(Pin::new(fut).poll(cx)).map_err(|_| { - PayloadError::Io(io::Error::new( - io::ErrorKind::Other, - "Blocking task was cancelled unexpectedly", - )) + PayloadError::Io(io::Error::other("Blocking task was cancelled unexpectedly")) })??; *this.decoder = Some(decoder); diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 735dca679..0da95c462 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -183,8 +183,7 @@ where if let Some(ref mut fut) = this.fut { let mut encoder = ready!(Pin::new(fut).poll(cx)) .map_err(|_| { - EncoderError::Io(io::Error::new( - io::ErrorKind::Other, + EncoderError::Io(io::Error::other( "Blocking task was cancelled unexpectedly", )) })? diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index 8ef2698a2..e4d640518 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -415,7 +415,7 @@ mod tests { #[test] fn test_as_response() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err: Error = ParseError::Io(orig).into(); assert_eq!( format!("{}", err), @@ -425,14 +425,14 @@ mod tests { #[test] fn test_error_display() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err = Error::new_io().with_cause(orig); assert_eq!("connection error: other", err.to_string()); } #[test] fn test_error_http_response() { - let orig = io::Error::new(io::ErrorKind::Other, "other"); + let orig = io::Error::other("other"); let err = Error::new_io().with_cause(orig); let resp: Response = err.into(); assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR); @@ -440,7 +440,7 @@ mod tests { #[test] fn test_payload_error() { - let err: PayloadError = io::Error::new(io::ErrorKind::Other, "ParseError").into(); + let err: PayloadError = io::Error::other("ParseError").into(); assert!(err.to_string().contains("ParseError")); let err = PayloadError::Incomplete(None); @@ -475,7 +475,7 @@ mod tests { #[test] fn test_from() { - from_and_cause!(io::Error::new(io::ErrorKind::Other, "other") => ParseError::Io(..)); + from_and_cause!(io::Error::other("other") => ParseError::Io(..)); from!(httparse::Error::HeaderName => ParseError::Header); from!(httparse::Error::HeaderName => ParseError::Header); from!(httparse::Error::HeaderValue => ParseError::Header); diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 77e34bcdc..81af7868b 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -310,10 +310,10 @@ impl MessageType for RequestHeadType { Version::HTTP_11 => "HTTP/1.1", Version::HTTP_2 => "HTTP/2.0", Version::HTTP_3 => "HTTP/3.0", - _ => return Err(io::Error::new(io::ErrorKind::Other, "unsupported version")), + _ => return Err(io::Error::other("Unsupported version")), } ) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err)) + .map_err(io::Error::other) } } @@ -433,7 +433,7 @@ impl TransferEncoding { buf.extend_from_slice(b"0\r\n\r\n"); } else { writeln!(helpers::MutWriter(buf), "{:X}\r", msg.len()) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; + .map_err(io::Error::other)?; buf.reserve(msg.len() + 2); buf.extend_from_slice(msg); diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index 0002f87e2..22618c9b3 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -776,10 +776,7 @@ where } Poll::Pending => break, Poll::Ready(Some(Err(err))) => { - return Poll::Ready(Some(Err(ProtocolError::Io(io::Error::new( - io::ErrorKind::Other, - format!("{err}"), - ))))); + return Poll::Ready(Some(Err(ProtocolError::Io(io::Error::other(err))))); } } } @@ -795,11 +792,10 @@ where } Some(frm) => { let msg = match frm { - Frame::Text(data) => { - Message::Text(ByteString::try_from(data).map_err(|err| { - ProtocolError::Io(io::Error::new(io::ErrorKind::Other, err)) - })?) - } + Frame::Text(data) => Message::Text( + ByteString::try_from(data) + .map_err(|err| ProtocolError::Io(io::Error::other(err)))?, + ), Frame::Binary(data) => Message::Binary(data), Frame::Ping(s) => Message::Ping(s), Frame::Pong(s) => Message::Pong(s), diff --git a/actix-web/src/server.rs b/actix-web/src/server.rs index 1ea4de4ca..ef6d26f94 100644 --- a/actix-web/src/server.rs +++ b/actix-web/src/server.rs @@ -1073,10 +1073,7 @@ fn bind_addrs(addrs: impl net::ToSocketAddrs, backlog: u32) -> io::Result