Skip to content

Commit b58cabe

Browse files
committed
errors: rename and extract TracingError
It was previously called `TracingProtocolError` and was contained in ExecutionError::ProtocolError. Since we now have a big picture of errors hierarchy, it's much clearer that `TracingError` should be a separate error type returned by tracing methods. ExecutionError should NOT depend on it. This commit renamed TracingProtocolError to TracingError, and changes the return type of Session::get_tracing_info(). New variant is introduced to `TracingError` - it contains an `ExecutionError`, which makes sense since we try to execute queries to system tracing tables.
1 parent 448502c commit b58cabe

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

scylla/src/client/session.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::cluster::node::{InternalKnownNode, KnownNode, NodeRef};
1616
use crate::cluster::{Cluster, ClusterNeatDebug, ClusterState};
1717
use crate::errors::{
1818
BadQuery, ExecutionError, MetadataError, NewSessionError, ProtocolError, RequestAttemptError,
19-
RequestError, TracingProtocolError, UseKeyspaceError,
19+
RequestError, TracingError, UseKeyspaceError,
2020
};
2121
use crate::frame::response::result;
2222
#[cfg(feature = "ssl")]
@@ -1742,7 +1742,7 @@ where
17421742
///
17431743
/// See [the book](https://rust-driver.docs.scylladb.com/stable/tracing/tracing.html)
17441744
/// for more information about query tracing
1745-
pub async fn get_tracing_info(&self, tracing_id: &Uuid) -> Result<TracingInfo, ExecutionError> {
1745+
pub async fn get_tracing_info(&self, tracing_id: &Uuid) -> Result<TracingInfo, TracingError> {
17461746
// tracing_info_fetch_attempts is NonZeroU32 so at least one attempt will be made
17471747
for _ in 0..self.tracing_info_fetch_attempts.get() {
17481748
let current_try: Option<TracingInfo> = self
@@ -1755,7 +1755,7 @@ where
17551755
};
17561756
}
17571757

1758-
Err(ProtocolError::Tracing(TracingProtocolError::EmptyResults).into())
1758+
Err(TracingError::EmptyResults)
17591759
}
17601760

17611761
/// Gets the name of the keyspace that is currently set, or `None` if no
@@ -1780,7 +1780,7 @@ where
17801780
&self,
17811781
tracing_id: &Uuid,
17821782
consistency: Option<Consistency>,
1783-
) -> Result<Option<TracingInfo>, ExecutionError> {
1783+
) -> Result<Option<TracingInfo>, TracingError> {
17841784
// Query system_traces.sessions for TracingInfo
17851785
let mut traces_session_query =
17861786
Query::new(crate::observability::tracing::TRACES_SESSION_QUERY_STR);
@@ -1801,17 +1801,15 @@ where
18011801
// Get tracing info
18021802
let maybe_tracing_info: Option<TracingInfo> = traces_session_res
18031803
.into_rows_result()
1804-
.map_err(|err| {
1805-
ProtocolError::Tracing(TracingProtocolError::TracesSessionIntoRowsResultError(err))
1806-
})?
1804+
.map_err(TracingError::TracesSessionIntoRowsResultError)?
18071805
.maybe_first_row()
18081806
.map_err(|err| match err {
18091807
MaybeFirstRowError::TypeCheckFailed(e) => {
1810-
ProtocolError::Tracing(TracingProtocolError::TracesSessionInvalidColumnType(e))
1808+
TracingError::TracesSessionInvalidColumnType(e)
1809+
}
1810+
MaybeFirstRowError::DeserializationFailed(e) => {
1811+
TracingError::TracesSessionDeserializationFailed(e)
18111812
}
1812-
MaybeFirstRowError::DeserializationFailed(e) => ProtocolError::Tracing(
1813-
TracingProtocolError::TracesSessionDeserializationFailed(e),
1814-
),
18151813
})?;
18161814

18171815
let mut tracing_info = match maybe_tracing_info {
@@ -1820,20 +1818,16 @@ where
18201818
};
18211819

18221820
// Get tracing events
1823-
let tracing_event_rows_result = traces_events_res.into_rows_result().map_err(|err| {
1824-
ProtocolError::Tracing(TracingProtocolError::TracesEventsIntoRowsResultError(err))
1825-
})?;
1821+
let tracing_event_rows_result = traces_events_res
1822+
.into_rows_result()
1823+
.map_err(TracingError::TracesEventsIntoRowsResultError)?;
18261824
let tracing_event_rows = tracing_event_rows_result.rows().map_err(|err| match err {
1827-
RowsError::TypeCheckFailed(err) => {
1828-
ProtocolError::Tracing(TracingProtocolError::TracesEventsInvalidColumnType(err))
1829-
}
1825+
RowsError::TypeCheckFailed(err) => TracingError::TracesEventsInvalidColumnType(err),
18301826
})?;
18311827

18321828
tracing_info.events = tracing_event_rows
18331829
.collect::<Result<_, _>>()
1834-
.map_err(|err| {
1835-
ProtocolError::Tracing(TracingProtocolError::TracesEventsDeserializationFailed(err))
1836-
})?;
1830+
.map_err(TracingError::TracesEventsDeserializationFailed)?;
18371831

18381832
if tracing_info.events.is_empty() {
18391833
return Ok(None);

scylla/src/errors.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ pub enum ProtocolError {
217217
#[error("Unable extract a partition key based on prepared statement's metadata")]
218218
PartitionKeyExtraction,
219219

220-
/// A protocol error occurred during tracing info fetch.
221-
#[error("Tracing info fetch protocol error: {0}")]
222-
Tracing(#[from] TracingProtocolError),
223-
224220
/// Driver tried to reprepare a statement in the batch, but the reprepared
225221
/// statement's id is not included in the batch.
226222
#[error("Reprepared statement's id does not exist in the batch.")]
@@ -267,10 +263,16 @@ pub enum SchemaVersionFetchError {
267263
SingleRowError(SingleRowError),
268264
}
269265

270-
/// A protocol error that occurred during tracing info fetch.
266+
/// An error that occurred during tracing info fetch.
271267
#[derive(Error, Debug, Clone)]
272268
#[non_exhaustive]
273-
pub enum TracingProtocolError {
269+
pub enum TracingError {
270+
/// Failed to execute query to either "system_traces.sessions" or "system_traces.events".
271+
#[error(
272+
"Failed to execute queries to \"system_traces.sessions\" or \"system_traces.events\" system tables: {0}"
273+
)]
274+
ExecutionError(#[from] ExecutionError),
275+
274276
/// Failed to convert result of system_traces.session query to rows result.
275277
#[error("Failed to convert result of system_traces.session query to rows result")]
276278
TracesSessionIntoRowsResultError(IntoRowsResultError),

0 commit comments

Comments
 (0)