Skip to content

Commit

Permalink
errors: make derive and impls of type-erased errors consistent
Browse files Browse the repository at this point in the history
Both SerializationError and DeserializationError derive Clone, Debug and Error.
They do not use `#error[]` do generate display impl.

We adjust the `TypeCheckError` and `BrokenConnectionError` so they
are consistent with other type-erased errors in this matter.
  • Loading branch information
muzarski committed Oct 15, 2024
1 parent 42c4c65 commit 0f715b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion scylla-cql/src/types/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ use thiserror::Error;
/// It won't be returned by the `Session` directly, but it might be nested
/// in the [`row::BuiltinTypeCheckError`].
#[derive(Debug, Clone, Error)]
#[error(transparent)]
pub struct TypeCheckError(pub(crate) Arc<dyn std::error::Error + Send + Sync>);

impl TypeCheckError {
Expand All @@ -218,6 +217,12 @@ impl TypeCheckError {
}
}

impl Display for TypeCheckError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "TypeCheckError: {}", self.0)
}
}

/// An error indicating that a failure happened during deserialization.
///
/// The error is type-erased so that the crate users can define their own
Expand Down
7 changes: 6 additions & 1 deletion scylla/src/transport/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ impl ConnectionSetupRequestError {
/// - failed to handle a server event (message received on stream -1)
/// - some low-level IO errors - e.g. driver failed to write data via socket
#[derive(Error, Debug, Clone)]
#[error("Connection broken, reason: {0}")]
pub struct BrokenConnectionError(Arc<dyn Error + Sync + Send>);

impl BrokenConnectionError {
Expand All @@ -734,6 +733,12 @@ impl BrokenConnectionError {
}
}

impl std::fmt::Display for BrokenConnectionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Connection broken, reason: {}", self.0)
}
}

/// A reason why connection was broken.
///
/// See [`BrokenConnectionError::downcast_ref()`].
Expand Down

0 comments on commit 0f715b3

Please sign in to comment.