From bf668bea86b4902800492d11eb4a1eaaec0ecde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Thu, 10 Oct 2024 17:06:13 +0200 Subject: [PATCH] errors: expose pub getters for type-erased errors Sometimes, user might want to downcast `Arc` to specific error type. Actually, there is a use case for this in cpp-rust-driver, where we need to define custom `SerializeRow` implementation. It returns a custom error type. We would like to match against it during rust-to-C error conversion - downcasting is thus required. --- scylla-cql/src/types/deserialize/mod.rs | 10 ++++++++++ scylla-cql/src/types/serialize/mod.rs | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/scylla-cql/src/types/deserialize/mod.rs b/scylla-cql/src/types/deserialize/mod.rs index 639fc62553..193b07a136 100644 --- a/scylla-cql/src/types/deserialize/mod.rs +++ b/scylla-cql/src/types/deserialize/mod.rs @@ -211,6 +211,11 @@ impl TypeCheckError { pub fn new(err: impl std::error::Error + Send + Sync + 'static) -> Self { Self(Arc::new(err)) } + + /// Retrieve an error reason. + pub fn get_reason(&self) -> &Arc { + &self.0 + } } /// An error indicating that a failure happened during deserialization. @@ -236,6 +241,11 @@ impl DeserializationError { pub fn new(err: impl Error + Send + Sync + 'static) -> Self { Self(Arc::new(err)) } + + /// Retrieve an error reason. + pub fn get_reason(&self) -> &Arc { + &self.0 + } } impl Display for DeserializationError { diff --git a/scylla-cql/src/types/serialize/mod.rs b/scylla-cql/src/types/serialize/mod.rs index b086dd5dcc..cae4f38e09 100644 --- a/scylla-cql/src/types/serialize/mod.rs +++ b/scylla-cql/src/types/serialize/mod.rs @@ -41,6 +41,11 @@ impl SerializationError { pub fn new(err: impl Error + Send + Sync + 'static) -> SerializationError { SerializationError(Arc::new(err)) } + + /// Retrieve an error reason. + pub fn get_reason(&self) -> &Arc { + &self.0 + } } impl Display for SerializationError {