diff --git a/proxy/src/binary/proxy.rs b/proxy/src/binary/proxy.rs index feca5ccf88..62fdc18207 100644 --- a/proxy/src/binary/proxy.rs +++ b/proxy/src/binary/proxy.rs @@ -314,9 +314,9 @@ pub async fn run() -> anyhow::Result<()> { None => { bail!("plain auth requires redis_notifications to be set"); } - Some(url) => Some( - ConnectionWithCredentialsProvider::new_with_static_credentials(url.to_string()), - ), + Some(url) => { + Some(ConnectionWithCredentialsProvider::new_with_static_credentials(url.clone())) + } }, ("irsa", _) => match (&args.redis_host, args.redis_port) { (Some(host), Some(port)) => Some( diff --git a/proxy/src/control_plane/client/mock.rs b/proxy/src/control_plane/client/mock.rs index ee722e839e..d3ab4abd0b 100644 --- a/proxy/src/control_plane/client/mock.rs +++ b/proxy/src/control_plane/client/mock.rs @@ -1,5 +1,6 @@ //! Mock console backend which relies on a user-provided postgres instance. +use std::io; use std::net::{IpAddr, Ipv4Addr}; use std::str::FromStr; use std::sync::Arc; @@ -22,7 +23,6 @@ use crate::control_plane::errors::{ }; use crate::control_plane::messages::MetricsAuxInfo; use crate::control_plane::{AccessBlockerFlags, AuthInfo, AuthSecret, CachedNodeInfo, NodeInfo}; -use crate::error::io_error; use crate::intern::RoleNameInt; use crate::types::{BranchId, EndpointId, ProjectId, RoleName}; use crate::url::ApiUrl; @@ -36,13 +36,13 @@ enum MockApiError { impl From for ControlPlaneError { fn from(e: MockApiError) -> Self { - io_error(e).into() + io::Error::other(e).into() } } impl From for ControlPlaneError { fn from(e: tokio_postgres::Error) -> Self { - io_error(e).into() + io::Error::other(e).into() } } diff --git a/proxy/src/control_plane/errors.rs b/proxy/src/control_plane/errors.rs index bc30cffd27..337ed665cc 100644 --- a/proxy/src/control_plane/errors.rs +++ b/proxy/src/control_plane/errors.rs @@ -1,8 +1,10 @@ +use std::io; + use thiserror::Error; use crate::control_plane::client::ApiLockError; use crate::control_plane::messages::{self, ControlPlaneErrorMessage, Reason}; -use crate::error::{ErrorKind, ReportableError, UserFacingError, io_error}; +use crate::error::{ErrorKind, ReportableError, UserFacingError}; use crate::proxy::retry::CouldRetry; /// A go-to error message which doesn't leak any detail. @@ -79,13 +81,13 @@ impl CouldRetry for ControlPlaneError { impl From for ControlPlaneError { fn from(e: reqwest::Error) -> Self { - io_error(e).into() + io::Error::other(e).into() } } impl From for ControlPlaneError { fn from(e: reqwest_middleware::Error) -> Self { - io_error(e).into() + io::Error::other(e).into() } } diff --git a/proxy/src/error.rs b/proxy/src/error.rs index 6a379499dc..aa02b211d9 100644 --- a/proxy/src/error.rs +++ b/proxy/src/error.rs @@ -1,15 +1,9 @@ -use std::error::Error as StdError; -use std::{fmt, io}; +use std::fmt; use anyhow::Context; use measured::FixedCardinalityLabel; use tokio::task::JoinError; -/// Upcast (almost) any error into an opaque [`io::Error`]. -pub(crate) fn io_error(e: impl Into>) -> io::Error { - io::Error::new(io::ErrorKind::Other, e) -} - /// Marks errors that may be safely shown to a client. /// This trait can be seen as a specialized version of [`ToString`]. /// diff --git a/proxy/src/protocol2.rs b/proxy/src/protocol2.rs index 41180fa6c1..b0603da379 100644 --- a/proxy/src/protocol2.rs +++ b/proxy/src/protocol2.rs @@ -163,8 +163,7 @@ fn process_proxy_payload( // other values are unassigned and must not be emitted by senders. Receivers // must drop connections presenting unexpected values here. #[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/6384 - _ => return Err(io::Error::new( - io::ErrorKind::Other, + _ => return Err(io::Error::other( format!( "invalid proxy protocol command 0x{:02X}. expected local (0x20) or proxy (0x21)", header.version_and_command @@ -178,21 +177,20 @@ fn process_proxy_payload( TCP_OVER_IPV4 | UDP_OVER_IPV4 => { let addr = payload .try_get::() - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, size_err))?; + .ok_or_else(|| io::Error::other(size_err))?; SocketAddr::from((addr.src_addr.get(), addr.src_port.get())) } TCP_OVER_IPV6 | UDP_OVER_IPV6 => { let addr = payload .try_get::() - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, size_err))?; + .ok_or_else(|| io::Error::other(size_err))?; SocketAddr::from((addr.src_addr.get(), addr.src_port.get())) } // unspecified or unix stream. ignore the addresses _ => { - return Err(io::Error::new( - io::ErrorKind::Other, + return Err(io::Error::other( "invalid proxy protocol address family/transport protocol.", )); } diff --git a/proxy/src/serverless/json.rs b/proxy/src/serverless/json.rs index fbd12ad9cb..7235fb6079 100644 --- a/proxy/src/serverless/json.rs +++ b/proxy/src/serverless/json.rs @@ -19,7 +19,7 @@ fn json_value_to_pg_text(value: &Value) -> Option { v @ (Value::Bool(_) | Value::Number(_) | Value::Object(_)) => Some(v.to_string()), // avoid escaping here, as we pass this as a parameter - Value::String(s) => Some(s.to_string()), + Value::String(s) => Some(s.clone()), // special care for arrays Value::Array(_) => json_array_to_pg_array(value), diff --git a/proxy/src/serverless/sql_over_http.rs b/proxy/src/serverless/sql_over_http.rs index 10e378a18d..972bf58d91 100644 --- a/proxy/src/serverless/sql_over_http.rs +++ b/proxy/src/serverless/sql_over_http.rs @@ -866,7 +866,7 @@ impl QueryData { let (inner, mut discard) = client.inner(); let cancel_token = inner.cancel_token(); - let res = match select( + match select( pin!(query_to_json( config, &mut *inner, @@ -889,7 +889,7 @@ impl QueryData { // The query failed with an error Either::Left((Err(e), __not_yet_cancelled)) => { discard.discard(); - return Err(e); + Err(e) } // The query was cancelled. Either::Right((_cancelled, query)) => { @@ -930,8 +930,7 @@ impl QueryData { } } } - }; - res + } } } diff --git a/proxy/src/serverless/websocket.rs b/proxy/src/serverless/websocket.rs index c4baeeb5cc..01d37d0eec 100644 --- a/proxy/src/serverless/websocket.rs +++ b/proxy/src/serverless/websocket.rs @@ -15,7 +15,7 @@ use tracing::warn; use crate::cancellation::CancellationHandler; use crate::config::ProxyConfig; use crate::context::RequestContext; -use crate::error::{ReportableError, io_error}; +use crate::error::ReportableError; use crate::metrics::Metrics; use crate::proxy::{ClientMode, ErrorSource, handle_client}; use crate::rate_limiter::EndpointRateLimiter; @@ -50,23 +50,23 @@ impl AsyncWrite for WebSocketRw { let this = self.project(); let mut stream = this.stream; - ready!(stream.as_mut().poll_ready(cx).map_err(io_error))?; + ready!(stream.as_mut().poll_ready(cx).map_err(io::Error::other))?; this.send.put(buf); match stream.as_mut().start_send(Frame::binary(this.send.split())) { Ok(()) => Poll::Ready(Ok(buf.len())), - Err(e) => Poll::Ready(Err(io_error(e))), + Err(e) => Poll::Ready(Err(io::Error::other(e))), } } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let stream = self.project().stream; - stream.poll_flush(cx).map_err(io_error) + stream.poll_flush(cx).map_err(io::Error::other) } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let stream = self.project().stream; - stream.poll_close(cx).map_err(io_error) + stream.poll_close(cx).map_err(io::Error::other) } } @@ -97,7 +97,7 @@ impl AsyncBufRead for WebSocketRw { } let res = ready!(this.stream.as_mut().poll_next(cx)); - match res.transpose().map_err(io_error)? { + match res.transpose().map_err(io::Error::other)? { Some(message) => match message.opcode { OpCode::Ping => {} OpCode::Pong => {} @@ -105,7 +105,7 @@ impl AsyncBufRead for WebSocketRw { // We expect to see only binary messages. let error = "unexpected text message in the websocket"; warn!(length = message.payload.len(), error); - return Poll::Ready(Err(io_error(error))); + return Poll::Ready(Err(io::Error::other(error))); } OpCode::Binary | OpCode::Continuation => { debug_assert!(this.recv.is_empty()); diff --git a/proxy/src/tls/server_config.rs b/proxy/src/tls/server_config.rs index eab9940e7d..5a95e69fde 100644 --- a/proxy/src/tls/server_config.rs +++ b/proxy/src/tls/server_config.rs @@ -173,7 +173,7 @@ impl CertResolver { } pub fn get_common_names(&self) -> HashSet { - self.certs.keys().map(|s| s.to_string()).collect() + self.certs.keys().cloned().collect() } }