Map ProtoConversionError to DispatchError
Map the protos ProtoConversionError to DispatchError variants, based on
error type.  This will allow for the use of the `?` operator in handlers
that use the FromProto and IntoBytes traits.
use protobuf::Message;
use crate::network::dispatch::{DispatchError, FromMessageBytes};
+use crate::protos::prelude::*;
// Implements FromMessageBytes for all protobuf Message values.
impl<M> FromMessageBytes for M
@@ -26,3 +27,14 @@ where
.map_err(|err| DispatchError::DeserializationError(err.to_string()))
}
}
+
+impl From<ProtoConversionError> for DispatchError {
+ fn from(err: ProtoConversionError) -> DispatchError {
+ match err {
+ ProtoConversionError::DeserializationError(s) => DispatchError::DeserializationError(s),
+ ProtoConversionError::SerializationError(s) => DispatchError::SerializationError(s),
+ // This is detected due to a protobuf that does not properly have fields set correctly.
+ ProtoConversionError::InvalidTypeError(s) => DispatchError::DeserializationError(s),
+ }
+ }
+}
