From cf46893907f28f2cda9a61c965f1791e231d2ea3 Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 18 Sep 2024 08:04:51 +0200 Subject: [PATCH] errors: move errors module to transport module Originally, all errors could be found under scylla::transport::errors. Let's retain the same path. --- scylla/src/history.rs | 4 ++-- scylla/src/lib.rs | 1 - scylla/src/statement/batch.rs | 2 +- scylla/src/statement/prepared_statement.rs | 2 +- scylla/src/transport/caching_session.rs | 2 +- scylla/src/transport/cluster.rs | 2 +- scylla/src/transport/connection.rs | 4 ++-- scylla/src/transport/connection_pool.rs | 4 +++- .../src/transport/downgrading_consistency_retry_policy.rs | 4 ++-- scylla/src/{ => transport}/errors.rs | 4 ++-- scylla/src/transport/iterator.rs | 4 ++-- scylla/src/transport/large_batch_statements_test.rs | 2 +- scylla/src/transport/load_balancing/default.rs | 4 ++-- scylla/src/transport/load_balancing/mod.rs | 2 +- scylla/src/transport/mod.rs | 1 + scylla/src/transport/node.rs | 2 +- scylla/src/transport/retry_policy.rs | 6 +++--- scylla/src/transport/session.rs | 4 ++-- scylla/src/transport/session_builder.rs | 2 +- scylla/src/transport/session_test.rs | 4 ++-- scylla/src/transport/speculative_execution.rs | 2 +- scylla/src/transport/topology.rs | 2 +- scylla/tests/integration/execution_profiles.rs | 2 +- scylla/tests/integration/new_session.rs | 2 +- scylla/tests/integration/tablets.rs | 2 +- 25 files changed, 36 insertions(+), 34 deletions(-) rename scylla/src/{ => transport}/errors.rs (99%) diff --git a/scylla/src/history.rs b/scylla/src/history.rs index af6cfeeae1..d4693163ef 100644 --- a/scylla/src/history.rs +++ b/scylla/src/history.rs @@ -7,7 +7,7 @@ use std::{ time::SystemTime, }; -use crate::{errors::QueryError, retry_policy::RetryDecision}; +use crate::{retry_policy::RetryDecision, transport::errors::QueryError}; use chrono::{DateTime, Utc}; use tracing::warn; @@ -455,10 +455,10 @@ mod tests { }; use crate::{ - errors::{DbError, QueryError}, query::Query, retry_policy::RetryDecision, test_utils::setup_tracing, + transport::errors::{DbError, QueryError}, utils::test_utils::unique_keyspace_name, }; diff --git a/scylla/src/lib.rs b/scylla/src/lib.rs index 76be6561b0..3adce0fc04 100644 --- a/scylla/src/lib.rs +++ b/scylla/src/lib.rs @@ -170,7 +170,6 @@ pub mod authentication; #[cfg(feature = "cloud")] pub mod cloud; -pub mod errors; pub mod history; pub mod routing; pub mod statement; diff --git a/scylla/src/statement/batch.rs b/scylla/src/statement/batch.rs index e9729ace5f..cda256a033 100644 --- a/scylla/src/statement/batch.rs +++ b/scylla/src/statement/batch.rs @@ -216,8 +216,8 @@ pub(crate) mod batch_values { use scylla_cql::types::serialize::row::SerializedValues; use scylla_cql::types::serialize::{RowWriter, SerializationError}; - use crate::errors::QueryError; use crate::routing::Token; + use crate::transport::errors::QueryError; use super::BatchStatement; diff --git a/scylla/src/statement/prepared_statement.rs b/scylla/src/statement/prepared_statement.rs index 17bbd3b35a..c83043d187 100644 --- a/scylla/src/statement/prepared_statement.rs +++ b/scylla/src/statement/prepared_statement.rs @@ -13,12 +13,12 @@ use thiserror::Error; use uuid::Uuid; use super::{PageSize, StatementConfig}; -use crate::errors::{BadQuery, QueryError}; use crate::frame::response::result::PreparedMetadata; use crate::frame::types::{Consistency, SerialConsistency}; use crate::history::HistoryListener; use crate::retry_policy::RetryPolicy; use crate::routing::Token; +use crate::transport::errors::{BadQuery, QueryError}; use crate::transport::execution_profile::ExecutionProfileHandle; use crate::transport::partitioner::{Partitioner, PartitionerHasher, PartitionerName}; diff --git a/scylla/src/transport/caching_session.rs b/scylla/src/transport/caching_session.rs index 91cd37802c..3fa352cd7d 100644 --- a/scylla/src/transport/caching_session.rs +++ b/scylla/src/transport/caching_session.rs @@ -1,8 +1,8 @@ use crate::batch::{Batch, BatchStatement}; -use crate::errors::QueryError; use crate::prepared_statement::PreparedStatement; use crate::query::Query; use crate::statement::{PagingState, PagingStateResponse}; +use crate::transport::errors::QueryError; use crate::transport::iterator::RowIterator; use crate::transport::partitioner::PartitionerName; use crate::{QueryResult, Session}; diff --git a/scylla/src/transport/cluster.rs b/scylla/src/transport/cluster.rs index 9421ec0c94..7ff6fb51c4 100644 --- a/scylla/src/transport/cluster.rs +++ b/scylla/src/transport/cluster.rs @@ -1,8 +1,8 @@ -use crate::errors::{BadQuery, NewSessionError, QueryError}; /// Cluster manages up to date information and connections to database nodes use crate::frame::response::event::{Event, StatusChangeEvent}; use crate::prepared_statement::TokenCalculationError; use crate::routing::{Shard, Token}; +use crate::transport::errors::{BadQuery, NewSessionError, QueryError}; use crate::transport::host_filter::HostFilter; use crate::transport::session::TABLET_CHANNEL_SIZE; use crate::transport::{ diff --git a/scylla/src/transport/connection.rs b/scylla/src/transport/connection.rs index 671ab9c898..21d2f3e21c 100644 --- a/scylla/src/transport/connection.rs +++ b/scylla/src/transport/connection.rs @@ -30,7 +30,7 @@ use tokio_openssl::SslStream; pub(crate) use ssl_config::SslConfig; use crate::authentication::AuthenticatorProvider; -use crate::errors::{ +use crate::transport::errors::{ BadKeyspaceName, BrokenConnectionError, BrokenConnectionErrorKind, ConnectionError, ConnectionSetupRequestError, ConnectionSetupRequestErrorKind, CqlEventHandlingError, DbError, QueryError, RequestError, ResponseParseError, TranslationError, UserRequestError, @@ -2709,7 +2709,7 @@ mod tests { #[ntest::timeout(20000)] #[cfg(not(scylla_cloud_tests))] async fn connection_is_closed_on_no_response_to_keepalives() { - use crate::errors::BrokenConnectionErrorKind; + use crate::transport::errors::BrokenConnectionErrorKind; setup_tracing(); diff --git a/scylla/src/transport/connection_pool.rs b/scylla/src/transport/connection_pool.rs index aa19b90427..e97fa85b73 100644 --- a/scylla/src/transport/connection_pool.rs +++ b/scylla/src/transport/connection_pool.rs @@ -1,8 +1,10 @@ #[cfg(feature = "cloud")] use crate::cloud::set_ssl_config_for_scylla_cloud_host; -use crate::errors::{BrokenConnectionErrorKind, ConnectionError, ConnectionPoolError, QueryError}; use crate::routing::{Shard, ShardCount, Sharder}; +use crate::transport::errors::{ + BrokenConnectionErrorKind, ConnectionError, ConnectionPoolError, QueryError, +}; use crate::transport::{ connection, connection::{Connection, ConnectionConfig, ErrorReceiver, VerifiedKeyspaceName}, diff --git a/scylla/src/transport/downgrading_consistency_retry_policy.rs b/scylla/src/transport/downgrading_consistency_retry_policy.rs index fa1dd7701b..7f2f326f10 100644 --- a/scylla/src/transport/downgrading_consistency_retry_policy.rs +++ b/scylla/src/transport/downgrading_consistency_retry_policy.rs @@ -2,8 +2,8 @@ use scylla_cql::Consistency; use tracing::debug; use crate::{ - errors::{DbError, QueryError, WriteType}, retry_policy::{QueryInfo, RetryDecision, RetryPolicy, RetrySession}, + transport::errors::{DbError, QueryError, WriteType}, }; /// Downgrading consistency retry policy - retries with lower consistency level if it knows\ @@ -185,8 +185,8 @@ mod tests { use bytes::Bytes; - use crate::errors::BadQuery; use crate::test_utils::setup_tracing; + use crate::transport::errors::BadQuery; use super::*; diff --git a/scylla/src/errors.rs b/scylla/src/transport/errors.rs similarity index 99% rename from scylla/src/errors.rs rename to scylla/src/transport/errors.rs index 00facdcd86..ee83bf3b10 100644 --- a/scylla/src/errors.rs +++ b/scylla/src/transport/errors.rs @@ -585,7 +585,7 @@ impl From for UserRequestError { /// - Driver was unable to allocate a stream id for a request /// /// This error type is only destined to narrow the return error type -/// of some functions that would previously return [`crate::errors::QueryError`]. +/// of some functions that would previously return [`crate::transport::errors::QueryError`]. #[derive(Error, Debug)] pub(crate) enum RequestError { #[error(transparent)] @@ -621,7 +621,7 @@ pub(crate) enum ResponseParseError { mod tests { use scylla_cql::Consistency; - use crate::errors::{DbError, QueryError, WriteType}; + use crate::transport::errors::{DbError, QueryError, WriteType}; #[test] fn write_type_from_str() { diff --git a/scylla/src/transport/iterator.rs b/scylla/src/transport/iterator.rs index ae3f939620..a4404e47e9 100644 --- a/scylla/src/transport/iterator.rs +++ b/scylla/src/transport/iterator.rs @@ -19,7 +19,6 @@ use super::execution_profile::ExecutionProfileInner; use super::session::RequestSpan; use crate::cql_to_rust::{FromRow, FromRowError}; -use crate::errors::{QueryError, UserRequestError}; use crate::frame::response::{ result, result::{ColumnSpec, Row, Rows}, @@ -29,6 +28,7 @@ use crate::statement::{prepared_statement::PreparedStatement, query::Query}; use crate::statement::{Consistency, PagingState, SerialConsistency}; use crate::transport::cluster::ClusterData; use crate::transport::connection::{Connection, NonErrorQueryResponse, QueryResponse}; +use crate::transport::errors::{QueryError, UserRequestError}; use crate::transport::load_balancing::{self, RoutingInfo}; use crate::transport::metrics::Metrics; use crate::transport::retry_policy::{QueryInfo, RetryDecision, RetrySession}; @@ -416,7 +416,7 @@ mod checked_channel_sender { use tokio::sync::mpsc; use uuid::Uuid; - use crate::errors::QueryError; + use crate::transport::errors::QueryError; use super::ReceivedPage; diff --git a/scylla/src/transport/large_batch_statements_test.rs b/scylla/src/transport/large_batch_statements_test.rs index 00c63d5113..7e8fc482c3 100644 --- a/scylla/src/transport/large_batch_statements_test.rs +++ b/scylla/src/transport/large_batch_statements_test.rs @@ -1,9 +1,9 @@ use assert_matches::assert_matches; use crate::batch::BatchType; -use crate::errors::{BadQuery, QueryError}; use crate::query::Query; use crate::test_utils::setup_tracing; +use crate::transport::errors::{BadQuery, QueryError}; use crate::{ batch::Batch, test_utils::{create_new_session_builder, unique_keyspace_name}, diff --git a/scylla/src/transport/load_balancing/default.rs b/scylla/src/transport/load_balancing/default.rs index 95ff6eaca0..8f717a0dff 100644 --- a/scylla/src/transport/load_balancing/default.rs +++ b/scylla/src/transport/load_balancing/default.rs @@ -3,8 +3,8 @@ pub use self::latency_awareness::LatencyAwarenessBuilder; use super::{FallbackPlan, LoadBalancingPolicy, NodeRef, RoutingInfo}; use crate::{ - errors::QueryError, routing::{Shard, Token}, + transport::errors::QueryError, transport::{cluster::ClusterData, locator::ReplicaSet, node::Node, topology::Strategy}, }; use itertools::{Either, Itertools}; @@ -2550,9 +2550,9 @@ mod latency_awareness { use uuid::Uuid; use crate::{ - errors::{DbError, QueryError}, load_balancing::NodeRef, routing::Shard, + transport::errors::{DbError, QueryError}, transport::node::Node, }; use std::{ diff --git a/scylla/src/transport/load_balancing/mod.rs b/scylla/src/transport/load_balancing/mod.rs index 6852c4fc61..72aaa1000e 100644 --- a/scylla/src/transport/load_balancing/mod.rs +++ b/scylla/src/transport/load_balancing/mod.rs @@ -4,8 +4,8 @@ use super::{cluster::ClusterData, NodeRef}; use crate::{ - errors::QueryError, routing::{Shard, Token}, + transport::errors::QueryError, }; use scylla_cql::frame::{response::result::TableSpec, types}; diff --git a/scylla/src/transport/mod.rs b/scylla/src/transport/mod.rs index 6324ca6f93..45befce153 100644 --- a/scylla/src/transport/mod.rs +++ b/scylla/src/transport/mod.rs @@ -3,6 +3,7 @@ mod cluster; pub(crate) mod connection; mod connection_pool; pub mod downgrading_consistency_retry_policy; +pub mod errors; pub mod execution_profile; pub mod host_filter; pub mod iterator; diff --git a/scylla/src/transport/node.rs b/scylla/src/transport/node.rs index d66deb0549..0568c9db7d 100644 --- a/scylla/src/transport/node.rs +++ b/scylla/src/transport/node.rs @@ -2,12 +2,12 @@ use tokio::net::lookup_host; use tracing::warn; use uuid::Uuid; -use crate::errors::{ConnectionPoolError, QueryError}; /// Node represents a cluster node along with it's data and connections use crate::routing::{Shard, Sharder}; use crate::transport::connection::Connection; use crate::transport::connection::VerifiedKeyspaceName; use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig}; +use crate::transport::errors::{ConnectionPoolError, QueryError}; use std::fmt::Display; use std::io; diff --git a/scylla/src/transport/retry_policy.rs b/scylla/src/transport/retry_policy.rs index a02dec65b1..75b3193c28 100644 --- a/scylla/src/transport/retry_policy.rs +++ b/scylla/src/transport/retry_policy.rs @@ -2,8 +2,8 @@ //! To decide when to retry a query the `Session` can use any object which implements //! the `RetryPolicy` trait -use crate::errors::{DbError, QueryError, WriteType}; use crate::frame::types::Consistency; +use crate::transport::errors::{DbError, QueryError, WriteType}; /// Information about a failed query pub struct QueryInfo<'a> { @@ -219,10 +219,10 @@ impl RetrySession for DefaultRetrySession { #[cfg(test)] mod tests { use super::{DefaultRetryPolicy, QueryInfo, RetryDecision, RetryPolicy}; - use crate::errors::{BadQuery, QueryError}; - use crate::errors::{DbError, WriteType}; use crate::statement::Consistency; use crate::test_utils::setup_tracing; + use crate::transport::errors::{BadQuery, QueryError}; + use crate::transport::errors::{DbError, WriteType}; use bytes::Bytes; use std::io::ErrorKind; use std::sync::Arc; diff --git a/scylla/src/transport/session.rs b/scylla/src/transport/session.rs index d385d7c67b..f420641d0b 100644 --- a/scylla/src/transport/session.rs +++ b/scylla/src/transport/session.rs @@ -5,10 +5,10 @@ use crate::batch::batch_values; #[cfg(feature = "cloud")] use crate::cloud::CloudConfig; -pub use crate::errors::TranslationError; -use crate::errors::{BadQuery, NewSessionError, QueryError, UserRequestError}; use crate::history; use crate::history::HistoryListener; +pub use crate::transport::errors::TranslationError; +use crate::transport::errors::{BadQuery, NewSessionError, QueryError, UserRequestError}; use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer}; use arc_swap::ArcSwapOption; use async_trait::async_trait; diff --git a/scylla/src/transport/session_builder.rs b/scylla/src/transport/session_builder.rs index e4f30b6e81..c5373f7c2d 100644 --- a/scylla/src/transport/session_builder.rs +++ b/scylla/src/transport/session_builder.rs @@ -7,7 +7,7 @@ use super::Compression; #[cfg(feature = "cloud")] use crate::cloud::{CloudConfig, CloudConfigError}; -use crate::errors::NewSessionError; +use crate::transport::errors::NewSessionError; #[cfg(feature = "cloud")] use crate::ExecutionProfile; diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 6aaab500a0..d8261791c4 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -1,6 +1,5 @@ use crate as scylla; use crate::batch::{Batch, BatchStatement}; -use crate::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::frame::response::result::Row; use crate::prepared_statement::PreparedStatement; use crate::query::Query; @@ -10,6 +9,7 @@ use crate::statement::Consistency; use crate::test_utils::{scylla_supports_tablets, setup_tracing}; use crate::tracing::TracingInfo; use crate::transport::cluster::Datacenter; +use crate::transport::errors::{BadKeyspaceName, BadQuery, DbError, QueryError}; use crate::transport::partitioner::{ calculate_token_for_partition_key, Murmur3Partitioner, Partitioner, PartitionerName, }; @@ -2526,7 +2526,7 @@ async fn test_rate_limit_exceeded_exception() { } } - use crate::errors::OperationType; + use crate::transport::errors::OperationType; match maybe_err.expect("Rate limit error didn't occur") { QueryError::DbError(DbError::RateLimitReached { op_type, .. }, _) => { diff --git a/scylla/src/transport/speculative_execution.rs b/scylla/src/transport/speculative_execution.rs index 6bf321b319..7a09d860db 100644 --- a/scylla/src/transport/speculative_execution.rs +++ b/scylla/src/transport/speculative_execution.rs @@ -5,7 +5,7 @@ use futures::{ use std::{future::Future, sync::Arc, time::Duration}; use tracing::{trace_span, warn, Instrument}; -use crate::errors::QueryError; +use crate::transport::errors::QueryError; use super::metrics::Metrics; diff --git a/scylla/src/transport/topology.rs b/scylla/src/transport/topology.rs index c578ee580a..f25935522d 100644 --- a/scylla/src/transport/topology.rs +++ b/scylla/src/transport/topology.rs @@ -1,9 +1,9 @@ -use crate::errors::{DbError, NewSessionError, QueryError}; use crate::frame::response::event::Event; use crate::routing::Token; use crate::statement::query::Query; use crate::transport::connection::{Connection, ConnectionConfig}; use crate::transport::connection_pool::{NodeConnectionPool, PoolConfig, PoolSize}; +use crate::transport::errors::{DbError, NewSessionError, QueryError}; use crate::transport::host_filter::HostFilter; use crate::transport::node::resolve_contact_points; use crate::utils::parse::{ParseErrorCause, ParseResult, ParserState}; diff --git a/scylla/tests/integration/execution_profiles.rs b/scylla/tests/integration/execution_profiles.rs index 95904b864a..948a1a1502 100644 --- a/scylla/tests/integration/execution_profiles.rs +++ b/scylla/tests/integration/execution_profiles.rs @@ -81,7 +81,7 @@ impl LoadBalancingPolicy for BoundToPredefinedNodePolicy { _query: &RoutingInfo, _latency: std::time::Duration, _node: NodeRef<'_>, - _error: &scylla::errors::QueryError, + _error: &scylla::transport::errors::QueryError, ) { } diff --git a/scylla/tests/integration/new_session.rs b/scylla/tests/integration/new_session.rs index 7f7f835379..6f734f0dab 100644 --- a/scylla/tests/integration/new_session.rs +++ b/scylla/tests/integration/new_session.rs @@ -1,7 +1,7 @@ use crate::utils::setup_tracing; use assert_matches::assert_matches; -use scylla::errors::NewSessionError; +use scylla::transport::errors::NewSessionError; use scylla::SessionBuilder; #[cfg(not(scylla_cloud_tests))] diff --git a/scylla/tests/integration/tablets.rs b/scylla/tests/integration/tablets.rs index 7ee8bc2bcb..3f1356840f 100644 --- a/scylla/tests/integration/tablets.rs +++ b/scylla/tests/integration/tablets.rs @@ -20,7 +20,7 @@ use scylla::ExecutionProfile; use scylla::QueryResult; use scylla::Session; -use scylla::errors::QueryError; +use scylla::transport::errors::QueryError; use scylla_proxy::{ Condition, ProxyError, Reaction, ResponseFrame, ResponseOpcode, ResponseReaction, ResponseRule, ShardAwareness, TargetShard, WorkerError,