Skip to content

Commit

Permalink
Output descriptor differences when ValidateStandardMessageType fails.
Browse files Browse the repository at this point in the history
Under normal circumstances this check is never expected to fail. Thus when it
does, it is valuable to know why exactly and not just the proto type.

PiperOrigin-RevId: 669265300
  • Loading branch information
CEL Dev Team authored and copybara-github committed Sep 4, 2024
1 parent 6e6f636 commit 3b5ce32
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/proto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_PROTO_UTIL_H_
#define THIRD_PARTY_CEL_CPP_INTERNAL_PROTO_UTIL_H_

#include <string>

#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/util/message_differencer.h"
#include "absl/status/status.h"
Expand Down Expand Up @@ -55,6 +57,8 @@ absl::Status ValidateStandardMessageType(
descriptor_from_pool->CopyTo(&descriptor_from_pool_proto);

google::protobuf::util::MessageDifferencer descriptor_differencer;
std::string differences;
descriptor_differencer.ReportDifferencesToString(&differences);
// The json_name is a compiler detail and does not change the message
// content. It can differ, e.g., between C++ and Go compilers. Hence ignore.
const google::protobuf::FieldDescriptor* json_name_field_desc =
Expand All @@ -67,8 +71,8 @@ absl::Status ValidateStandardMessageType(
descriptor_from_pool_proto)) {
return absl::FailedPreconditionError(absl::StrFormat(
"The descriptor for '%s' in the descriptor pool differs from the "
"compiled-in generated version",
descriptor->full_name()));
"compiled-in generated version as follows: %s",
descriptor->full_name(), differences));
}
} else {
// Lite runtime. Just verify the message exists.
Expand Down

0 comments on commit 3b5ce32

Please # to comment.