Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed Dec 11, 2024
1 parent c880b6a commit 5ce1531
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
26 changes: 9 additions & 17 deletions crates/store/re_log_types/src/protobuf_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use re_protos::invalid_field;
use re_protos::missing_field;
use re_protos::TypeConversionError;
use re_protos::{invalid_field, missing_field};
use std::sync::Arc;

impl From<crate::EntityPath> for re_protos::common::v0::EntityPath {
Expand All @@ -15,11 +14,8 @@ impl TryFrom<re_protos::common::v0::EntityPath> for crate::EntityPath {
type Error = TypeConversionError;

fn try_from(value: re_protos::common::v0::EntityPath) -> Result<Self, Self::Error> {
Self::parse_strict(&value.path).map_err(|err| TypeConversionError::InvalidField {
type_name: "rerun.common.v0.EntityPath",
field_name: "path",
reason: err.to_string(),
})
Self::parse_strict(&value.path)
.map_err(|err| invalid_field!(re_protos::common::v0::EntityPath, "path", err))
}
}

Expand Down Expand Up @@ -301,11 +297,7 @@ impl TryFrom<re_protos::log_msg::v0::StoreSource> for crate::StoreSource {
.extra
.ok_or(missing_field!(re_protos::log_msg::v0::StoreSource, "extra"))?;
let description = String::from_utf8(description.payload).map_err(|err| {
invalid_field!(
re_protos::log_msg::v0::StoreSource,
"extra",
err.to_string()
)
invalid_field!(re_protos::log_msg::v0::StoreSource, "extra", err)
})?;
Ok(Self::Other(description))
}
Expand Down Expand Up @@ -379,11 +371,11 @@ impl TryFrom<re_protos::log_msg::v0::FileSource> for crate::FileSource {
force_store_info: false,
}),
FileSourceKind::Sdk => Ok(Self::Sdk),
FileSourceKind::UnknownSource => Err(TypeConversionError::InvalidField {
type_name: "rerun.log_msg.v0.FileSource",
field_name: "kind",
reason: "unknown kind".to_owned(),
}),
FileSourceKind::UnknownSource => Err(invalid_field!(
re_protos::log_msg::v0::FileSource,
"kind",
"unknown kind",
)),
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/store/re_protos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ pub mod remote_store {

#[derive(Debug, thiserror::Error)]
pub enum TypeConversionError {
#[error("missing required field: {type_name}.{field_name}")]
#[error("missing required field: {package_name}.{type_name}.{field_name}")]
MissingField {
package_name: &'static str,
type_name: &'static str,
field_name: &'static str,
},

#[error("invalid value for field {type_name}.{field_name}: {reason}")]
#[error("invalid value for field {package_name}.{type_name}.{field_name}: {reason}")]
InvalidField {
package_name: &'static str,
type_name: &'static str,
field_name: &'static str,
reason: String,
Expand Down Expand Up @@ -90,6 +91,7 @@ impl TypeConversionError {
#[inline]
pub fn invalid_field<T: prost::Name>(field_name: &'static str, reason: &impl ToString) -> Self {
Self::InvalidField {
package_name: T::PACKAGE,
type_name: T::NAME,
field_name,
reason: reason.to_string(),
Expand Down

0 comments on commit 5ce1531

Please sign in to comment.