Github user phrocker commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/350#discussion_r192165690
  
    --- Diff: libminifi/src/core/yaml/YamlConfiguration.cpp ---
    @@ -782,29 +783,59 @@ void 
YamlConfiguration::parsePropertiesNodeYaml(YAML::Node *propertiesNode,
         }
       }
     
    +  validateComponentProperties(processor, component_name, yaml_section);
    +}
    +
    +void YamlConfiguration::validateComponentProperties(const 
std::shared_ptr<ConfigurableComponent> &component,
    +                                                    const std::string 
&component_name,
    +                                                    const std::string 
&yaml_section) const {
    +  const auto &component_properties = component->getProperties();
    +
       // Validate required properties
    -  for (const auto &prop_pair : processor->getProperties()) {
    +  for (const auto &prop_pair : component_properties) {
         if (prop_pair.second.getRequired()) {
    -      const auto &val = prop_pair.second.getValue();
    -
    -      if (val.empty()) {
    -        // Build a helpful error message for the user so they can fix the
    -        // invalid YAML config file, using the component name if present
    -        std::string err_msg =
    -            "Unable to parse configuration file for component named '"
    -                + component_name
    -                + "' because required property '" + 
prop_pair.second.getName() + "' is not set";
    -        if (!yaml_section.empty()) {
    -          err_msg += " [in '" + yaml_section + "' section of configuration 
file]";
    -        }
    -        logging::LOG_ERROR(logger_) << err_msg;
    +      if (prop_pair.second.getValue().empty()) {
    +        std::string reason("required property '");
    +        reason.append(prop_pair.second.getName());
    +        reason.append("' is not set");
    +        raiseComponentError(component_name, yaml_section, reason);
    +      }
    +    }
    +  }
     
    -        throw std::invalid_argument(err_msg);
    +  // Validate regex properties
    +  for (const auto &prop_pair : component_properties) {
    +    const auto &prop_regex_str = prop_pair.second.getValidRegex();
    +
    +    if (!prop_regex_str.empty()) {
    +      std::regex prop_regex(prop_regex_str);
    +      if (!std::regex_match(prop_pair.second.getValue(), prop_regex)) {
    +        std::string reason("property '");
    +        reason.append(prop_pair.second.getName());
    +        reason.append("' does not match validation pattern '");
    +        reason.append(prop_regex_str);
    +        reason.append("'");
    +        raiseComponentError(component_name, yaml_section, reason);
           }
         }
       }
     }
     
    +void YamlConfiguration::raiseComponentError(const std::string 
&component_name,
    +                                            const std::string 
&yaml_section,
    +                                            const std::string &reason) 
const {
    +  std::string err_msg = "Unable to parse configuration file for component 
named '";
    --- End diff --
    
    A string stream or the like may make this more readable. 


---

Reply via email to