fix: Re-export prost errors instead of wrapping them

pull/24376/head
Carol (Nichols || Goulding) 2021-10-15 11:49:29 -04:00
parent c64403d8b5
commit 26484309e0
4 changed files with 19 additions and 25 deletions

View File

@ -1,7 +1,7 @@
use crate::{
google::{FieldViolation, FieldViolationExt, FromFieldOpt},
influxdata::iox::management::v1 as management,
ProstError,
DecodeError, EncodeError,
};
use data_types::{
database_rules::{
@ -125,8 +125,8 @@ impl TryFrom<management::RoutingConfig> for RoutingConfig {
/// Decode database rules that were encoded using `encode_persisted_database_rules`
pub fn decode_persisted_database_rules(
bytes: prost::bytes::Bytes,
) -> Result<management::PersistedDatabaseRules, ProstError> {
Ok(prost::Message::decode(bytes)?)
) -> Result<management::PersistedDatabaseRules, DecodeError> {
prost::Message::decode(bytes)
}
/// TEMPORARY FOR TRANSITION PURPOSES - if decoding rules file as `PersistedDatabaseRules` (which
@ -135,16 +135,16 @@ pub fn decode_persisted_database_rules(
/// `PersistedDatabaseRules`.
pub fn decode_database_rules(
bytes: prost::bytes::Bytes,
) -> Result<management::DatabaseRules, ProstError> {
Ok(prost::Message::decode(bytes)?)
) -> Result<management::DatabaseRules, DecodeError> {
prost::Message::decode(bytes)
}
/// Encode database rules into a serialized format suitable for storage in object store
pub fn encode_persisted_database_rules(
rules: &management::PersistedDatabaseRules,
bytes: &mut prost::bytes::BytesMut,
) -> Result<(), ProstError> {
Ok(prost::Message::encode(rules, bytes)?)
) -> Result<(), EncodeError> {
prost::Message::encode(rules, bytes)
}
impl From<WriteBufferConnection> for management::WriteBufferConnection {

View File

@ -155,17 +155,7 @@ pub mod job;
#[cfg(feature = "data_types_conversions")]
pub mod server_config;
use thiserror::Error;
/// Wrapper around a `prost` error so that users of this crate do not have a direct dependency
/// on the prost crate.
#[derive(Debug, Error)]
pub enum ProstError {
#[error("failed to encode protobuf: {0}")]
EncodeError(#[from] prost::EncodeError),
#[error("failed to decode protobuf: {0}")]
DecodeError(#[from] prost::DecodeError),
}
pub use prost::{DecodeError, EncodeError};
#[cfg(test)]
mod tests {

View File

@ -1,16 +1,16 @@
use crate::{influxdata::iox::management::v1 as management, ProstError};
use crate::{influxdata::iox::management::v1 as management, DecodeError, EncodeError};
/// Decode server config that was encoded using `encode_persisted_server_config`
pub fn decode_persisted_server_config(
bytes: prost::bytes::Bytes,
) -> Result<management::ServerConfig, ProstError> {
Ok(prost::Message::decode(bytes)?)
) -> Result<management::ServerConfig, DecodeError> {
prost::Message::decode(bytes)
}
/// Encode server config into a serialized format suitable for storage in object store
pub fn encode_persisted_server_config(
server_config: &management::ServerConfig,
bytes: &mut prost::bytes::BytesMut,
) -> Result<(), ProstError> {
Ok(prost::Message::encode(server_config, bytes)?)
) -> Result<(), EncodeError> {
prost::Message::encode(server_config, bytes)
}

View File

@ -20,10 +20,14 @@ pub enum Error {
},
#[snafu(display("error deserializing database rules: {}", source))]
Deserialization { source: generated_types::ProstError },
Deserialization {
source: generated_types::DecodeError,
},
#[snafu(display("error serializing database rules: {}", source))]
Serialization { source: generated_types::ProstError },
Serialization {
source: generated_types::EncodeError,
},
#[snafu(display("error fetching rules: {}", source))]
RulesFetch { source: object_store::Error },