Skip to content

Commit

Permalink
errors: map UnknownNamedParameterError to CassError
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
muzarski committed Dec 3, 2024
1 parent 7df6da8 commit a5334cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion scylla-rust-wrapper/src/cass_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use scylla::transport::errors::*;
// Re-export error types.
pub(crate) use crate::cass_error_types::{CassError, CassErrorSource};
use crate::query_error::CassErrorResult;
use crate::statement::UnknownNamedParameterError;

pub trait ToCassError {
fn to_cass_error(&self) -> CassError;
Expand Down Expand Up @@ -94,7 +95,14 @@ impl ToCassError for BadQuery {
BadQuery::ValuesTooLongForKey(_usize, _usize2) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::BadKeyspaceName(_bad_keyspace_name) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::Other(_other_query) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::SerializationError(_) => CassError::CASS_ERROR_LAST_ENTRY,
BadQuery::SerializationError(e) => {
if e.downcast_ref::<UnknownNamedParameterError>().is_some() {
// It means that our custom `UnknownNamedParameterError` was returned.
CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST
} else {
CassError::CASS_ERROR_LAST_ENTRY
}
}
BadQuery::TooManyQueriesInBatchStatement(_) => CassError::CASS_ERROR_LAST_ENTRY,
// BadQuery is non_exhaustive
// For now, since all other variants return LAST_ENTRY,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/integration/tests/test_named_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ CASSANDRA_INTEGRATION_TEST_F(NamedParametersTests, SimpleStatementInvalidName) {
insert_statement.bind<Uuid>("named_uuid", value_uuid_);
insert_statement.bind<Blob>("named_blob", value_blob_);
insert_statement.bind<List<Float> >("named_list_floats", value_list_floats_);
EXPECT_EQ(CASS_ERROR_SERVER_INVALID_QUERY,
EXPECT_EQ(CASS_ERROR_LIB_NAME_DOES_NOT_EXIST,
session_.execute(insert_statement, false).error_code());
}

Expand Down

0 comments on commit a5334cf

Please sign in to comment.