Skip to content

Commit c7bff2d

Browse files
committed
Added RequestTimeout errors variant
This shall represent the situation when the timeout provided elapsed before the query was completed.
1 parent 6f45cba commit c7bff2d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

scylla-cql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ scylla-macros = { version = "0.1.1", path = "../scylla-macros"}
1414
byteorder = "1.3.4"
1515
bytes = "1.0.1"
1616
num_enum = "0.5"
17-
tokio = { version = "1.12", features = ["io-util"] }
17+
tokio = { version = "1.12", features = ["io-util", "time"] }
1818
snap = "1.0"
1919
uuid = "1.0"
2020
thiserror = "1.0"

scylla-cql/src/errors.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ pub enum QueryError {
4040

4141
#[error("Unable to allocate stream id")]
4242
UnableToAllocStreamId,
43+
44+
/// Client timeout occurred before any response arrived
45+
#[error("Request timeout: {0}")]
46+
RequestTimeout(String),
4347
}
4448

4549
/// An error sent from the database in response to a query
@@ -292,6 +296,11 @@ pub enum NewSessionError {
292296

293297
#[error("Unable to allocate stream id")]
294298
UnableToAllocStreamId,
299+
300+
/// Client timeout occurred before a response arrived for some query
301+
/// during `Session` creation.
302+
#[error("Client timeout: {0}")]
303+
RequestTimeout(String),
295304
}
296305

297306
/// Invalid keyspace name given to `Session::use_keyspace()`
@@ -340,6 +349,12 @@ impl From<FrameError> for QueryError {
340349
}
341350
}
342351

352+
impl From<tokio::time::error::Elapsed> for QueryError {
353+
fn from(timer_error: tokio::time::error::Elapsed) -> QueryError {
354+
QueryError::RequestTimeout(format!("{}", timer_error))
355+
}
356+
}
357+
343358
impl From<std::io::Error> for NewSessionError {
344359
fn from(io_error: std::io::Error) -> NewSessionError {
345360
NewSessionError::IoError(Arc::new(io_error))
@@ -359,6 +374,7 @@ impl From<QueryError> for NewSessionError {
359374
NewSessionError::TooManyOrphanedStreamIds(ids)
360375
}
361376
QueryError::UnableToAllocStreamId => NewSessionError::UnableToAllocStreamId,
377+
QueryError::RequestTimeout(msg) => NewSessionError::RequestTimeout(msg),
362378
}
363379
}
364380
}

0 commit comments

Comments
 (0)