sqlx_scylladb_core/
error.rs1use std::error::Error as StdError;
2
3use scylla::{
4 cluster::metadata::ColumnType,
5 errors::{
6 DeserializationError, ExecutionError, IntoRowsResultError, NewSessionError,
7 PagerExecutionError, PrepareError, RowsError, SerializationError, TypeCheckError,
8 UseKeyspaceError,
9 },
10};
11use sqlx::error::{DatabaseError, ErrorKind};
12use sqlx_core::ext::ustr::UStr;
13use thiserror::Error;
14
15#[derive(Debug, Error)]
17#[error(transparent)]
18pub enum ScyllaDBError {
19 #[error("Configuration error. {0}")]
21 ConfigurationError(String),
22 NewSessionError(#[from] NewSessionError),
24 UseKeyspaceError(#[from] UseKeyspaceError),
26 PrepareError(#[from] PrepareError),
28 IntoRowsResultError(#[from] IntoRowsResultError),
30 RowsError(#[from] RowsError),
32 TypeCheckError(#[from] TypeCheckError),
34 SerializationError(#[from] SerializationError),
36 DeserializationError(#[from] DeserializationError),
38 ExecutionError(#[from] ExecutionError),
40 PagerExecutionError(#[from] PagerExecutionError),
42 #[error("Transaction is not started.")]
44 TransactionNotStarted,
45 #[error("Column index out of bounds. the len is {len}, but the index is {index}")]
47 ColumnIndexOutOfBounds {
48 index: usize,
50 len: usize,
52 },
53 #[error("Column type is mismatched. expect: {expect:?}, actual: {actual:?}")]
55 ColumnTypeError {
56 expect: ColumnType<'static>,
58 actual: ColumnType<'static>,
60 },
61 #[error("Failed to acquire migration lock.")]
63 MigrationLockError,
64 #[error("Mismatched column type {0}: {1:?}..")]
66 MismatchedColumnTypeError(UStr, ColumnType<'static>),
67 #[error("Column type '{0:?}' is not supported.")]
69 ColumnTypeNotSupportedError(ColumnType<'static>),
70 #[error("{0:?} is null.")]
72 NullValueError(UStr),
73 #[error("Exclusive lock error.")]
75 ExclusiveLockError,
76}
77
78impl DatabaseError for ScyllaDBError {
79 fn message(&self) -> &str {
80 match self {
81 ScyllaDBError::ConfigurationError(message) => &message,
82 ScyllaDBError::NewSessionError(_) => "New session error.",
83 ScyllaDBError::UseKeyspaceError(_) => "Use keyspace error.",
84 ScyllaDBError::PrepareError(_) => "Prepare error.",
85 ScyllaDBError::IntoRowsResultError(_) => "Into rows result error.",
86 ScyllaDBError::RowsError(_) => "Rows error.",
87 ScyllaDBError::TypeCheckError(_) => "Type check error.",
88 ScyllaDBError::SerializationError(_) => "Serialization error.",
89 ScyllaDBError::DeserializationError(_) => "Deserialization error.",
90 ScyllaDBError::ExecutionError(_) => "Execution error.",
91 ScyllaDBError::PagerExecutionError(_) => "Pager execution error.",
92 ScyllaDBError::TransactionNotStarted => "Transaction is not started.",
93 ScyllaDBError::ColumnIndexOutOfBounds { index: _, len: _ } => {
94 "Column index out of bounds."
95 }
96 ScyllaDBError::ColumnTypeError {
97 expect: _,
98 actual: _,
99 } => "Column type error.",
100 ScyllaDBError::MigrationLockError => "Migration lock error.",
101 ScyllaDBError::MismatchedColumnTypeError(_, _) => "Mismatched column type.",
102 ScyllaDBError::ColumnTypeNotSupportedError(_) => "Column type not supported.",
103 ScyllaDBError::NullValueError(_) => "Null value error",
104 ScyllaDBError::ExclusiveLockError => "Exclusive lock error.",
105 }
106 }
107
108 fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
109 self
110 }
111
112 fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
113 self
114 }
115
116 fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
117 self
118 }
119
120 fn kind(&self) -> ErrorKind {
121 ErrorKind::Other
122 }
123}