|
26 | 26 | #include "absl/strings/str_join.h" |
27 | 27 | #include "absl/strings/str_split.h" |
28 | 28 | #include "absl/strings/string_view.h" |
| 29 | +#include "absl/strings/substitute.h" |
29 | 30 | #include "absl/types/span.h" |
30 | 31 | #include "google/protobuf/cpp_features.pb.h" |
31 | 32 | #include "google/protobuf/descriptor.h" |
@@ -364,26 +365,36 @@ absl::Status ValidateMergedFeatures(const FeatureSet& features) { |
364 | 365 |
|
365 | 366 | void ValidateSingleFeatureLifetimes( |
366 | 367 | Edition edition, absl::string_view full_name, |
367 | | - const FieldOptions::FeatureSupport& support, |
| 368 | + const FieldOptions::FeatureSupport& feature_support, |
368 | 369 | FeatureResolver::ValidationResults& results) { |
369 | 370 | // Skip fields that don't have feature support specified. |
370 | | - if (&support == &FieldOptions::FeatureSupport::default_instance()) return; |
371 | | - |
372 | | - if (edition < support.edition_introduced()) { |
373 | | - results.errors.emplace_back( |
374 | | - absl::StrCat("Feature ", full_name, " wasn't introduced until edition ", |
375 | | - support.edition_introduced(), |
376 | | - " and can't be used in edition ", edition)); |
377 | | - } |
378 | | - if (support.has_edition_removed() && edition >= support.edition_removed()) { |
379 | | - results.errors.emplace_back(absl::StrCat( |
380 | | - "Feature ", full_name, " has been removed in edition ", |
381 | | - support.edition_removed(), " and can't be used in edition ", edition)); |
382 | | - } else if (support.has_edition_deprecated() && |
383 | | - edition >= support.edition_deprecated()) { |
384 | | - results.warnings.emplace_back(absl::StrCat( |
385 | | - "Feature ", full_name, " has been deprecated in edition ", |
386 | | - support.edition_deprecated(), ": ", support.deprecation_warning())); |
| 371 | + if (&feature_support == &FieldOptions::FeatureSupport::default_instance()) |
| 372 | + return; |
| 373 | + // safe guarding new features that aren't available yet |
| 374 | + if (edition < feature_support.edition_introduced()) { |
| 375 | + std::string error_message = absl::Substitute( |
| 376 | + "$0 wasn't introduced until edition $1 and can't be used in " |
| 377 | + "edition $2", |
| 378 | + full_name, feature_support.edition_introduced(), edition); |
| 379 | + results.errors.emplace_back(std::move(error_message)); |
| 380 | + } |
| 381 | + if (feature_support.has_edition_removed() && |
| 382 | + edition >= feature_support.edition_removed()) { |
| 383 | + std::string error_message = absl::Substitute( |
| 384 | + "$0 has been removed in edition $1$2", full_name, |
| 385 | + feature_support.edition_removed(), |
| 386 | + (feature_support.has_removal_error()) |
| 387 | + ? absl::StrCat(": ", feature_support.removal_error()) |
| 388 | + : ""); |
| 389 | + results.errors.emplace_back(std::move(error_message)); |
| 390 | + } else if (feature_support.has_edition_deprecated() && |
| 391 | + edition >= feature_support.edition_deprecated()) { |
| 392 | + std::string error_message = absl::Substitute( |
| 393 | + "$0 has been deprecated in edition " |
| 394 | + "$1: $2", |
| 395 | + full_name, feature_support.edition_deprecated(), |
| 396 | + feature_support.deprecation_warning()); |
| 397 | + results.warnings.emplace_back(std::move(error_message)); |
387 | 398 | } |
388 | 399 | } |
389 | 400 |
|
|
0 commit comments