Skip to content

Commit 3f9351b

Browse files
committed
cass_error: MetadataError better conversion
`MetadataFetchErrorKind::NextRowError` was previously always converted to `CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE`, which is not appropriate for all cases. This commit refactors the conversion to handle different cases of `NextRowError` more appropriately, depending on the specific error encountered.
1 parent a3c6827 commit 3f9351b

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

scylla-rust-wrapper/src/cass_error.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use libc::c_char;
66
use scylla::deserialize::DeserializationError;
77
use scylla::errors::{
88
BadKeyspaceName, BadQuery, ConnectionPoolError, DbError, ExecutionError, MetadataError,
9-
MetadataFetchErrorKind, NewSessionError, PrepareError, RequestAttemptError, SerializationError,
10-
WriteType,
9+
MetadataFetchErrorKind, NewSessionError, NextRowError, PrepareError, RequestAttemptError,
10+
RequestError, SerializationError, WriteType,
1111
};
1212
use scylla::frame::frame_errors::ResultMetadataAndRowsCountParseError;
1313
use scylla::statement::Consistency;
@@ -187,8 +187,39 @@ impl ToCassError for MetadataError {
187187
}
188188
MetadataFetchErrorKind::PrepareError(e) => e.to_cass_error(),
189189
MetadataFetchErrorKind::SerializationError(e) => e.to_cass_error(),
190-
MetadataFetchErrorKind::NextRowError(_) => {
191-
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE
190+
MetadataFetchErrorKind::NextRowError(e) => {
191+
match e {
192+
// CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE
193+
NextRowError::NextPageError(next_page_error) => match next_page_error {
194+
scylla::errors::NextPageError::PartitionKeyError(_) => {
195+
CassError::CASS_ERROR_LIB_MESSAGE_ENCODE
196+
}
197+
scylla::errors::NextPageError::RequestFailure(e) => {
198+
match e {
199+
RequestError::EmptyPlan => {
200+
CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE
201+
}
202+
RequestError::ConnectionPoolError(e) => e.to_cass_error(),
203+
RequestError::RequestTimeout(_) => {
204+
CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT
205+
}
206+
RequestError::LastAttemptError(e) => e.to_cass_error(),
207+
// non_exhaustive
208+
_ => CassError::CASS_ERROR_LAST_ENTRY,
209+
}
210+
}
211+
scylla::errors::NextPageError::ResultMetadataParseError(_) => {
212+
CassError::CASS_ERROR_LIB_INVALID_DATA
213+
}
214+
// non_exhaustive
215+
_ => CassError::CASS_ERROR_LAST_ENTRY,
216+
},
217+
NextRowError::RowDeserializationError(_) => {
218+
CassError::CASS_ERROR_LIB_INVALID_DATA
219+
}
220+
// non_exhaustive
221+
_ => CassError::CASS_ERROR_LAST_ENTRY,
222+
}
192223
}
193224

194225
// non_exhaustive

0 commit comments

Comments
 (0)