use tokio::sync::oneshot::error::RecvError;
#[derive(thiserror::Error, Clone, Debug)]
pub enum ScyllaxError {
#[error("Scylla Query error: {0}")]
Scylla(#[from] scylla::transport::errors::QueryError),
#[error("Scylla single row typed error: {0}")]
SingleRowTyped(#[from] scylla::transport::query_result::SingleRowTypedError),
#[error("No rows found")]
NoRowsFound,
#[error("Failed to build query: {0}")]
BuildUpsertQueryError(#[from] BuildUpsertQueryError),
#[error("Failed to serialize values: {0}")]
SerializedValues(#[from] scylla::frame::value::SerializeValuesError),
#[error("Receiver error: {0}")]
ReceiverError(#[from] RecvError),
}
#[derive(thiserror::Error, Clone, Debug)]
pub enum BuildUpsertQueryError {
#[error("Too many values when adding {field}")]
TooManyValues {
field: String,
},
#[error("Can't mix named and unnamed values")]
MixingNamedAndNotNamedValues,
#[error("Value for {field} is too big")]
ValueTooBig {
field: String,
},
#[error("Failed to serialize value for {field}")]
ParseError {
field: String,
},
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_build_upsert_query_error() {
assert_eq!(
"Value for foo is too big",
BuildUpsertQueryError::ValueTooBig {
field: "foo".to_string()
}
.to_string()
);
assert_eq!(
"Failed to serialize value for foo",
BuildUpsertQueryError::ParseError {
field: "foo".to_string()
}
.to_string()
);
assert_eq!(
"Too many values when adding foo",
BuildUpsertQueryError::TooManyValues {
field: "foo".to_string()
}
.to_string()
);
assert_eq!(
"Can't mix named and unnamed values",
BuildUpsertQueryError::MixingNamedAndNotNamedValues.to_string()
);
}
#[test]
fn test_scyllax_error() {
assert_eq!("No rows found", ScyllaxError::NoRowsFound.to_string());
assert_eq!(
"Failed to build query: Value for foo is too big",
ScyllaxError::BuildUpsertQueryError(BuildUpsertQueryError::ValueTooBig {
field: "foo".to_string()
})
.to_string()
);
}
}