adamdebreceni commented on a change in pull request #1220:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1220#discussion_r765577036



##########
File path: libminifi/include/core/yaml/CheckRequiredField.h
##########
@@ -49,7 +53,23 @@ namespace yaml {
  *                               not present in 'yamlNode'
  */
 void checkRequiredField(
-    const YAML::Node *yamlNode, const std::string &fieldName, const 
std::shared_ptr<logging::Logger>& logger, const std::string &yamlSection = "", 
const std::string &errorMessage = "");
+    const YAML::Node *yamlNode, const std::string &fieldName, const 
std::shared_ptr<logging::Logger>& logger, const std::string &yamlSection = "", 
std::string errorMessage = "");
+
+template<typename T>
+T parseRequiredField(const YAML::Node* yamlNode,
+    const std::vector<std::string>& alternateNames, const 
std::shared_ptr<logging::Logger>& logger,
+    const std::string &yamlSection, std::function<T(const YAML::Node&)> 
parser, std::string errorMessage = "") {
+  for (const auto& name : alternateNames) {
+    if (yaml::isFieldPresent(yamlNode, name)) {
+      return parser((*yamlNode)[name]);
+    }
+  }
+  if (errorMessage.empty()) {
+    errorMessage = buildErrorMessage(yamlNode, alternateNames, yamlSection);
+  }
+  logger->log_error(errorMessage.c_str());
+  throw std::invalid_argument(errorMessage);
+}

Review comment:
       I think we might as well drop the `parseRequiredField` and keep the 
`getRequiredField`, we wouldn't need to template anything and could move all 
implementations to the cpp file
   
   `getRequiredField(...).as<std::string>()` even looks better than 
`parseRequiredField(..., [] (const auto& node) {return node.as<std::string>()}` 
IMO




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to