You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2021/02/09 17:54:42 UTC

[nifi-minifi-cpp] branch main updated: MINIFICPP-1485 Improve 'exclusive property' error message

This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new a52faa5  MINIFICPP-1485 Improve 'exclusive property' error message
a52faa5 is described below

commit a52faa5136031abfcc321a44fbcd954ee0f73764
Author: Ferenc Gerlits <fg...@gmail.com>
AuthorDate: Tue Feb 9 18:53:42 2021 +0100

    MINIFICPP-1485 Improve 'exclusive property' error message
    
    Signed-off-by: Marton Szasz <sz...@gmail.com>
    
    Closes #999
---
 .../tests/unit/YamlConfigurationTests.cpp          |  2 +-
 libminifi/src/core/yaml/YamlConfiguration.cpp      | 31 +++++++---------------
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
index dc71c5a..c9ce42c 100644
--- a/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
+++ b/extensions/standard-processors/tests/unit/YamlConfigurationTests.cpp
@@ -709,7 +709,7 @@ TEST_CASE("Test Exclusive Property 2", "[YamlConfigurationExclusiveProperty2]")
   } catch (const std::exception &e) {
     config_failed = true;
     REQUIRE("Unable to parse configuration file for component named 'component A' because "
-        "property 'Prop B' is exclusive of property 'Prop A' values matching '^val.*$' "
+        "property 'Prop B' must not be set when the value of property 'Prop A' matches '^val.*$' "
         "[in 'section A' section of configuration file]" == std::string(e.what()));
   }
   REQUIRE(config_failed);
diff --git a/libminifi/src/core/yaml/YamlConfiguration.cpp b/libminifi/src/core/yaml/YamlConfiguration.cpp
index 2a9b17d..dbb2b4f 100644
--- a/libminifi/src/core/yaml/YamlConfiguration.cpp
+++ b/libminifi/src/core/yaml/YamlConfiguration.cpp
@@ -895,13 +895,11 @@ void YamlConfiguration::validateComponentProperties(const std::shared_ptr<Config
   for (const auto &prop_pair : component_properties) {
     if (prop_pair.second.getRequired()) {
       if (prop_pair.second.getValue().to_string().empty()) {
-        std::stringstream reason;
-        reason << "required property '" << prop_pair.second.getName() << "' is not set";
-        raiseComponentError(component_name, yaml_section, reason.str());
+        std::string reason = utils::StringUtils::join_pack("required property '", prop_pair.second.getName(), "' is not set");
+        raiseComponentError(component_name, yaml_section, reason);
       } else if (!prop_pair.second.getValue().validate(prop_pair.first).valid()) {
-        std::stringstream reason;
-        reason << "Property '" << prop_pair.second.getName() << "' is not valid";
-        raiseComponentError(component_name, yaml_section, reason.str());
+        std::string reason = utils::StringUtils::join_pack("the value '", prop_pair.first, "' is not valid for property '", prop_pair.second.getName(), "'");
+        raiseComponentError(component_name, yaml_section, reason);
       }
     }
   }
@@ -916,11 +914,8 @@ void YamlConfiguration::validateComponentProperties(const std::shared_ptr<Config
 
     for (const auto &dep_prop_key : dep_props) {
       if (component_properties.at(dep_prop_key).getValue().to_string().empty()) {
-        std::string reason("property '");
-        reason.append(prop_pair.second.getName());
-        reason.append("' depends on property '");
-        reason.append(dep_prop_key);
-        reason.append("' which is not set");
+        std::string reason = utils::StringUtils::join_pack("property '", prop_pair.second.getName(),
+            "' depends on property '", dep_prop_key, "' which is not set");
         raiseComponentError(component_name, yaml_section, reason);
       }
     }
@@ -938,13 +933,8 @@ void YamlConfiguration::validateComponentProperties(const std::shared_ptr<Config
     for (const auto &excl_pair : excl_props) {
       std::regex excl_expr(excl_pair.second);
       if (std::regex_match(component_properties.at(excl_pair.first).getValue().to_string(), excl_expr)) {
-        std::string reason("property '");
-        reason.append(prop_pair.second.getName());
-        reason.append("' is exclusive of property '");
-        reason.append(excl_pair.first);
-        reason.append("' values matching '");
-        reason.append(excl_pair.second);
-        reason.append("'");
+        std::string reason = utils::StringUtils::join_pack("property '", prop_pair.second.getName(),
+            "' must not be set when the value of property '", excl_pair.first, "' matches '", excl_pair.second, "'");
         raiseComponentError(component_name, yaml_section, reason);
       }
     }
@@ -957,9 +947,8 @@ void YamlConfiguration::validateComponentProperties(const std::shared_ptr<Config
     if (!prop_regex_str.empty()) {
       std::regex prop_regex(prop_regex_str);
       if (!std::regex_match(prop_pair.second.getValue().to_string(), prop_regex)) {
-        std::stringstream reason;
-        reason << "property '" << prop_pair.second.getName() << "' does not match validation pattern '" << prop_regex_str << "'";
-        raiseComponentError(component_name, yaml_section, reason.str());
+        std::string reason = utils::StringUtils::join_pack("property '", prop_pair.second.getName(), "' does not match validation pattern '", prop_regex_str, "'");
+        raiseComponentError(component_name, yaml_section, reason);
       }
     }
   }