Skip to content

Commit 55e12ac

Browse files
committed
errors: replace stringified RequestTimeout variant with two new variants
Introduced: - RequestTimeout(std::time::Duration) - for requests that timed out with provided client timeout - SchemaAgreementTimeout(std::time::Duration) - for schema agreement timeouts
1 parent 7a11683 commit 55e12ac

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

scylla/src/client/session.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,13 +1979,7 @@ where
19791979
Some(timeout) => tokio::time::timeout(timeout, runner)
19801980
.await
19811981
.map(|res| res.map_err(RequestError::into_query_error))
1982-
.unwrap_or_else(|e| {
1983-
Err(QueryError::RequestTimeout(format!(
1984-
"Request took longer than {}ms: {}",
1985-
timeout.as_millis(),
1986-
e
1987-
)))
1988-
}),
1982+
.unwrap_or_else(|_| Err(QueryError::RequestTimeout(timeout))),
19891983
None => runner.await.map_err(RequestError::into_query_error),
19901984
};
19911985

@@ -2144,8 +2138,8 @@ where
21442138
self.await_schema_agreement_indefinitely(),
21452139
)
21462140
.await
2147-
.unwrap_or(Err(QueryError::RequestTimeout(
2148-
"schema agreement not reached in time".to_owned(),
2141+
.unwrap_or(Err(QueryError::SchemaAgreementTimeout(
2142+
self.schema_agreement_timeout,
21492143
)))
21502144
}
21512145

scylla/src/errors.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ pub enum QueryError {
103103
#[error("Unable to allocate stream id")]
104104
UnableToAllocStreamId,
105105

106-
/// Client timeout occurred before any response arrived
107-
#[error("Request timeout: {0}")]
108-
RequestTimeout(String),
106+
/// Failed to run a request within a provided client timeout.
107+
#[error(
108+
"Request execution exceeded a client timeout of {}ms",
109+
std::time::Duration::as_millis(.0)
110+
)]
111+
RequestTimeout(std::time::Duration),
112+
113+
/// Schema agreement timed out.
114+
#[error("Schema agreement exceeded {}ms", std::time::Duration::as_millis(.0))]
115+
SchemaAgreementTimeout(std::time::Duration),
109116

110117
// TODO: This should not belong here, but it requires changes to error types
111118
// returned in async iterator API. This should be handled in separate PR.
@@ -139,12 +146,6 @@ impl From<SerializationError> for QueryError {
139146
}
140147
}
141148

142-
impl From<tokio::time::error::Elapsed> for QueryError {
143-
fn from(timer_error: tokio::time::error::Elapsed) -> QueryError {
144-
QueryError::RequestTimeout(format!("{}", timer_error))
145-
}
146-
}
147-
148149
impl From<QueryError> for NewSessionError {
149150
fn from(query_error: QueryError) -> NewSessionError {
150151
match query_error {
@@ -161,7 +162,8 @@ impl From<QueryError> for NewSessionError {
161162
QueryError::TimeoutError => NewSessionError::TimeoutError,
162163
QueryError::BrokenConnection(e) => NewSessionError::BrokenConnection(e),
163164
QueryError::UnableToAllocStreamId => NewSessionError::UnableToAllocStreamId,
164-
QueryError::RequestTimeout(msg) => NewSessionError::RequestTimeout(msg),
165+
QueryError::RequestTimeout(dur) => NewSessionError::RequestTimeout(dur),
166+
QueryError::SchemaAgreementTimeout(dur) => NewSessionError::SchemaAgreementTimeout(dur),
165167
#[allow(deprecated)]
166168
QueryError::IntoLegacyQueryResultError(e) => {
167169
NewSessionError::IntoLegacyQueryResultError(e)
@@ -254,10 +256,16 @@ pub enum NewSessionError {
254256
#[error("Unable to allocate stream id")]
255257
UnableToAllocStreamId,
256258

257-
/// Client timeout occurred before a response arrived for some query
258-
/// during `Session` creation.
259-
#[error("Client timeout: {0}")]
260-
RequestTimeout(String),
259+
/// Failed to run a request within a provided client timeout.
260+
#[error(
261+
"Request execution exceeded a client timeout of {}ms",
262+
std::time::Duration::as_millis(.0)
263+
)]
264+
RequestTimeout(std::time::Duration),
265+
266+
/// Schema agreement timed out.
267+
#[error("Schema agreement exceeded {}ms", std::time::Duration::as_millis(.0))]
268+
SchemaAgreementTimeout(std::time::Duration),
261269

262270
// TODO: This should not belong here, but it requires changes to error types
263271
// returned in async iterator API. This should be handled in separate PR.

0 commit comments

Comments
 (0)