Improve error message in the crate mapping code.

Before this change we would just crash without further details if the crate mapping file or crate mapping was not found.

PiperOrigin-RevId: 601694688
pull/15588/head
Jakob Buchgraber 10 months ago committed by Copybara-Service
parent 85938aa654
commit 5ecfdd76ef
  1. 9
      src/google/protobuf/compiler/rust/context.h
  2. 1
      src/google/protobuf/compiler/rust/crate_mapping.cc

@ -13,6 +13,7 @@
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_log.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
@ -69,7 +70,13 @@ class RustGeneratorContext {
}
absl::string_view ImportPathToCrateName(absl::string_view import_path) const {
return import_path_to_crate_name_.at(import_path);
auto it = import_path_to_crate_name_.find(import_path);
if (it == import_path_to_crate_name_.end()) {
ABSL_LOG(FATAL) << "Path " << import_path
<< " not found in crate mapping. Crate mapping has "
<< import_path_to_crate_name_.size() << " entries";
}
return it->second;
}
private:

@ -12,6 +12,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/rust/context.h"

Loading…
Cancel
Save