Skip to content

Commit 293a032

Browse files
committed
errors: map UnknownNamedParameterError to CassError
Unfortunately, there is no other way to inspect what's inside the SerializationError (since its only member is private), other than just converting it to string and checking string contents. We probably need to make this member public in rust-driver (so users can downcast to their custom errors). In this commit, we also adjust one of the NamedParameterTests to this change. We are going to enable this test suite in the next commit.
1 parent 8af4204 commit 293a032

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

scylla-rust-wrapper/src/cass_error.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use scylla::transport::errors::*;
22

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

67
impl From<&QueryError> for CassError {
78
fn from(error: &QueryError) -> Self {
@@ -71,7 +72,14 @@ impl From<&BadQuery> for CassError {
7172
BadQuery::ValuesTooLongForKey(_usize, _usize2) => CassError::CASS_ERROR_LAST_ENTRY,
7273
BadQuery::BadKeyspaceName(_bad_keyspace_name) => CassError::CASS_ERROR_LAST_ENTRY,
7374
BadQuery::Other(_other_query) => CassError::CASS_ERROR_LAST_ENTRY,
74-
BadQuery::SerializationError(_) => CassError::CASS_ERROR_LAST_ENTRY,
75+
BadQuery::SerializationError(e) => {
76+
if e.downcast_ref::<UnknownNamedParameterError>().is_some() {
77+
// It means that our custom `UnknownNamedParameterError` was returned.
78+
CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST
79+
} else {
80+
CassError::CASS_ERROR_LAST_ENTRY
81+
}
82+
}
7583
BadQuery::TooManyQueriesInBatchStatement(_) => CassError::CASS_ERROR_LAST_ENTRY,
7684
// BadQuery is non_exhaustive
7785
// For now, since all other variants return LAST_ENTRY,

tests/src/integration/tests/test_named_parameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ CASSANDRA_INTEGRATION_TEST_F(NamedParametersTests, SimpleStatementInvalidName) {
204204
insert_statement.bind<Uuid>("named_uuid", value_uuid_);
205205
insert_statement.bind<Blob>("named_blob", value_blob_);
206206
insert_statement.bind<List<Float> >("named_list_floats", value_list_floats_);
207-
EXPECT_EQ(CASS_ERROR_SERVER_INVALID_QUERY,
207+
EXPECT_EQ(CASS_ERROR_LIB_NAME_DOES_NOT_EXIST,
208208
session_.execute(insert_statement, false).error_code());
209209
}
210210

0 commit comments

Comments
 (0)