Skip to content

Commit 7e044a8

Browse files
authored
Merge pull request #206 from muzarski/bump-0.15
bump rust-driver to 0.15 (with eager deserialization)
2 parents 739855a + a8b0637 commit 7e044a8

File tree

7 files changed

+506
-262
lines changed

7 files changed

+506
-262
lines changed

scylla-rust-wrapper/Cargo.lock

Lines changed: 72 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scylla-rust-wrapper/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["database"]
1010
license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
13-
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd", features = [
13+
scylla = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.15.0", features = [
1414
"ssl",
1515
] }
1616
tokio = { version = "1.27.0", features = ["full"] }
@@ -26,13 +26,14 @@ openssl = "0.10.32"
2626
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
2727
tracing = "0.1.37"
2828
futures = "0.3"
29+
thiserror = "1.0"
2930

3031
[build-dependencies]
3132
bindgen = "0.65"
3233
chrono = "0.4.20"
3334

3435
[dev-dependencies]
35-
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "64b4afcd" }
36+
scylla-proxy = { git = "https://github.com/scylladb/scylla-rust-driver.git", rev = "v0.15.0" }
3637

3738
assert_matches = "1.5.0"
3839
ntest = "0.9.3"

scylla-rust-wrapper/src/cass_error.rs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,35 @@ use scylla::transport::errors::*;
22

33
// Re-export error types.
44
pub(crate) use crate::cass_error_types::{CassError, CassErrorSource};
5+
use crate::query_error::CassErrorResult;
56

6-
impl From<&QueryError> for CassError {
7-
fn from(error: &QueryError) -> Self {
8-
match error {
9-
QueryError::DbError(db_error, _string) => CassError::from(db_error),
10-
QueryError::BadQuery(bad_query) => CassError::from(bad_query),
7+
pub trait ToCassError {
8+
fn to_cass_error(&self) -> CassError;
9+
}
10+
11+
impl ToCassError for CassErrorResult {
12+
fn to_cass_error(&self) -> CassError {
13+
match self {
14+
CassErrorResult::Query(query_error) => query_error.to_cass_error(),
15+
16+
// TODO:
17+
// For now let's leave these as LIB_INVALID_DATA.
18+
// I don't see any variants that would make more sense.
19+
// TBH, I'm almost sure that we should introduce additional enum variants
20+
// of CassError in the future ~ muzarski.
21+
CassErrorResult::ResultMetadataLazyDeserialization(_) => {
22+
CassError::CASS_ERROR_LIB_INVALID_DATA
23+
}
24+
CassErrorResult::Deserialization(_) => CassError::CASS_ERROR_LIB_INVALID_DATA,
25+
}
26+
}
27+
}
28+
29+
impl ToCassError for QueryError {
30+
fn to_cass_error(&self) -> CassError {
31+
match self {
32+
QueryError::DbError(db_error, _string) => db_error.to_cass_error(),
33+
QueryError::BadQuery(bad_query) => bad_query.to_cass_error(),
1134
QueryError::ProtocolError(_str) => CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR,
1235
QueryError::TimeoutError => CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT, // This may be either read or write timeout error
1336
QueryError::UnableToAllocStreamId => CassError::CASS_ERROR_LIB_NO_STREAMS,
@@ -32,9 +55,9 @@ impl From<&QueryError> for CassError {
3255
}
3356
}
3457

35-
impl From<&DbError> for CassError {
36-
fn from(error: &DbError) -> Self {
37-
match error {
58+
impl ToCassError for DbError {
59+
fn to_cass_error(&self) -> CassError {
60+
match self {
3861
DbError::ServerError => CassError::CASS_ERROR_SERVER_SERVER_ERROR,
3962
DbError::ProtocolError => CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR,
4063
DbError::AuthenticationError => CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS,
@@ -62,9 +85,9 @@ impl From<&DbError> for CassError {
6285
}
6386
}
6487

65-
impl From<&BadQuery> for CassError {
66-
fn from(error: &BadQuery) -> Self {
67-
match error {
88+
impl ToCassError for BadQuery {
89+
fn to_cass_error(&self) -> CassError {
90+
match self {
6891
BadQuery::SerializeValuesError(_serialize_values_error) => {
6992
CassError::CASS_ERROR_LAST_ENTRY
7093
}
@@ -81,9 +104,9 @@ impl From<&BadQuery> for CassError {
81104
}
82105
}
83106

84-
impl From<&NewSessionError> for CassError {
85-
fn from(error: &NewSessionError) -> Self {
86-
match error {
107+
impl ToCassError for NewSessionError {
108+
fn to_cass_error(&self) -> CassError {
109+
match self {
87110
NewSessionError::FailedToResolveAnyHostname(_hostnames) => {
88111
CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE
89112
}
@@ -117,9 +140,9 @@ impl From<&NewSessionError> for CassError {
117140
}
118141
}
119142

120-
impl From<&BadKeyspaceName> for CassError {
121-
fn from(error: &BadKeyspaceName) -> Self {
122-
match error {
143+
impl ToCassError for BadKeyspaceName {
144+
fn to_cass_error(&self) -> CassError {
145+
match self {
123146
BadKeyspaceName::Empty => CassError::CASS_ERROR_LAST_ENTRY,
124147
BadKeyspaceName::TooLong(_string, _usize) => CassError::CASS_ERROR_LAST_ENTRY,
125148
BadKeyspaceName::IllegalCharacter(_string, _char) => CassError::CASS_ERROR_LAST_ENTRY,
@@ -133,6 +156,12 @@ pub trait CassErrorMessage {
133156
fn msg(&self) -> String;
134157
}
135158

159+
impl CassErrorMessage for CassErrorResult {
160+
fn msg(&self) -> String {
161+
self.to_string()
162+
}
163+
}
164+
136165
impl CassErrorMessage for QueryError {
137166
fn msg(&self) -> String {
138167
self.to_string()

scylla-rust-wrapper/src/future.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::argconv::*;
22
use crate::cass_error::CassError;
33
use crate::cass_error::CassErrorMessage;
4+
use crate::cass_error::ToCassError;
45
use crate::prepared::CassPrepared;
56
use crate::query_error::CassErrorResult;
67
use crate::query_result::CassResult;
@@ -320,7 +321,7 @@ pub unsafe extern "C" fn cass_future_ready(future_raw: *const CassFuture) -> cas
320321
#[no_mangle]
321322
pub unsafe extern "C" fn cass_future_error_code(future_raw: *const CassFuture) -> CassError {
322323
ptr_to_ref(future_raw).with_waited_result(|r: &mut CassFutureResult| match r {
323-
Ok(CassResultValue::QueryError(err)) => CassError::from(err.as_ref()),
324+
Ok(CassResultValue::QueryError(err)) => err.to_cass_error(),
324325
Err((err, _)) => *err,
325326
_ => CassError::CASS_OK,
326327
})

0 commit comments

Comments
 (0)