diff --git a/proto/src/writer/backend.rs b/proto/src/writer/backend.rs index 4cbbdc8..c4203ab 100644 --- a/proto/src/writer/backend.rs +++ b/proto/src/writer/backend.rs @@ -3,10 +3,11 @@ use crate::writer::oneway::OneWayProtoWriter; use crate::writer::protowriter::ProtoWriter; use async_trait::async_trait; use tokio::io::{AsyncWrite, AsyncWriteExt}; +use crate::writer::errors::ProtoWriteError; #[async_trait] pub trait BackendProtoWriter: OneWayProtoWriter { - async fn write_ssl_reject(&mut self) -> anyhow::Result<()>; + async fn write_ssl_reject(&mut self) -> Result<(), ProtoWriteError>; } #[async_trait] @@ -14,7 +15,7 @@ impl BackendProtoWriter for ProtoWriter where W: AsyncWrite + Unpin + Send, { - async fn write_ssl_reject(&mut self) -> anyhow::Result<()> { + async fn write_ssl_reject(&mut self) -> Result<(), ProtoWriteError> { self.inner.write_u8(b'N').await?; Ok(()) } diff --git a/proto/src/writer/errors.rs b/proto/src/writer/errors.rs new file mode 100644 index 0000000..f014a69 --- /dev/null +++ b/proto/src/writer/errors.rs @@ -0,0 +1,11 @@ +use thiserror::Error; +use tokio::io; +use crate::message::errors::ProtoSerializeError; + +#[derive(Debug, Error)] +pub enum ProtoWriteError { + #[error("writing to socket failed")] + Io(#[from] io::Error), + #[error("serialization of inner data failed")] + Serialize(#[from] ProtoSerializeError), +} diff --git a/proto/src/writer/mod.rs b/proto/src/writer/mod.rs index 3f16f05..f5cd408 100644 --- a/proto/src/writer/mod.rs +++ b/proto/src/writer/mod.rs @@ -2,3 +2,4 @@ pub mod backend; pub mod frontend; pub mod oneway; pub mod protowriter; +pub mod errors; diff --git a/proto/src/writer/oneway.rs b/proto/src/writer/oneway.rs index 1649fd8..17bb5ee 100644 --- a/proto/src/writer/oneway.rs +++ b/proto/src/writer/oneway.rs @@ -2,13 +2,14 @@ use crate::message::proto_message::ProtoMessage; use crate::writer::protowriter::ProtoWriter; use async_trait::async_trait; use tokio::io::{AsyncWrite, AsyncWriteExt}; +use crate::writer::errors::ProtoWriteError; #[async_trait] pub trait OneWayProtoWriter where T: ProtoMessage, { - async fn write_proto(&mut self, message: T) -> anyhow::Result<()>; + async fn write_proto(&mut self, message: T) -> Result<(), ProtoWriteError>; } #[async_trait] @@ -17,7 +18,7 @@ where W: AsyncWrite + Unpin + Send, T: ProtoMessage + Send + 'static, { - async fn write_proto(&mut self, message: T) -> anyhow::Result<()> { + async fn write_proto(&mut self, message: T) -> Result<(), ProtoWriteError> { let variant = message.variant(); let mut data = message.serialize()?; let length = data.len() as i32 + 4; diff --git a/proto/src/writer/protowriter.rs b/proto/src/writer/protowriter.rs index 848a727..27aa9e4 100644 --- a/proto/src/writer/protowriter.rs +++ b/proto/src/writer/protowriter.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use tokio::io; use tokio::io::{AsyncWrite, AsyncWriteExt}; pub struct ProtoWriter @@ -19,7 +20,7 @@ where #[async_trait] pub trait ProtoFlush { - async fn flush(&mut self) -> anyhow::Result<()>; + async fn flush(&mut self) -> Result<(), io::Error>; } #[async_trait] @@ -27,7 +28,7 @@ impl ProtoFlush for ProtoWriter where W: AsyncWrite + Unpin + Send, { - async fn flush(&mut self) -> anyhow::Result<()> { + async fn flush(&mut self) -> Result<(), io::Error> { self.inner.flush().await?; Ok(()) }