bneradt commented on code in PR #14122:
URL: https://github.com/apache/trafficserver/pull/14122#discussion_r4683167500


##########
src/proxy/Plugin.cc:
##########
@@ -632,11 +646,22 @@ plugin_yaml_init(bool validateOnly)
     cleanup_inline_configs();
   }
 
+  // A plugin.yaml that cannot be loaded as written stops startup, rather than
+  // leaving traffic_server running without the plugins it names. A config
+  // check only reports it.
+  auto fail = [validateOnly](const std::string &message) {
+    if (validateOnly) {
+      Error("%s", message.c_str());
+    } else {
+      Emergency("%s", message.c_str());
+    }
+    return false;
+  };
+
   yaml_path = RecConfigReadConfigPath(nullptr, ts::filename::PLUGIN_YAML);
   if (access(yaml_path, R_OK) != 0) {
     if (errno != ENOENT) {
-      Error("%s: %s", ts::filename::PLUGIN_YAML, strerror(errno));
-      return false;
+      return fail(std::string(ts::filename::PLUGIN_YAML) + ": " + 
strerror(errno));

Review Comment:
   **[P2] Route file read failures through the startup diagnostic.** A 
directory at `plugin.yaml` passes `access(R_OK)` on Linux. I confirmed with the 
bundled yaml-cpp that `YAML::LoadFile()` then throws `std::ios_base::failure` 
during the read. The `YAML::Exception` catch misses it, so startup aborts 
before reaching `fail()`. Please handle stream errors at the load boundary or 
check the file type before parsing, and cover this case in the startup test.



##########
src/proxy/Plugin.cc:
##########
@@ -474,30 +482,36 @@ parse_plugin_yaml(const char *yaml_path)
   for (const auto &node : root["plugins"]) {
     PluginYAMLEntry entry;
 
-    if (!node["path"]) {
-      result.errata.note("plugin entry #{} missing required 'path' field", 
seq_idx + 1);
-      return result;
-    }
-    entry.path = node["path"].as<std::string>();
+    // A wrong node type or value (a scalar entry, "enabled: maybe") makes 
yaml-cpp throw.
+    try {
+      if (!node["path"]) {
+        result.errata.note("plugin entry #{} missing required 'path' field", 
seq_idx + 1);
+        return result;
+      }
+      entry.path = node["path"].as<std::string>();
 
-    if (auto n = node["enabled"]; n) {
-      entry.enabled = n.as<bool>();
-    }
-    if (auto n = node["load_order"]; n) {
-      entry.load_order = n.as<int>();
-    }
-    if (auto n = node["params"]; n && n.IsSequence()) {
-      for (const auto &p : n) {
-        entry.params.emplace_back(p.as<std::string>());
+      if (auto n = node["enabled"]; n) {
+        entry.enabled = n.as<bool>();
       }
-    }
-    if (auto n = node["config"]; n) {
-      if (n.IsScalar()) {
-        entry.config_literal = n.as<std::string>();
-      } else {
-        result.errata.note("plugin '{}': 'config' must be a scalar (use 
literal block '|' for multi-line content)", entry.path);
-        return result;
+      if (auto n = node["load_order"]; n) {
+        entry.load_order = n.as<int>();
+      }
+      if (auto n = node["params"]; n && n.IsSequence()) {

Review Comment:
   **[P2] Report a non-list `params` value.** The documented type is a 
sequence, but an entry with scalar or mapping `params` takes neither branch and 
starts the plugin with no arguments. That can silently drop its configuration 
even though the new load-error behavior is intended to catch wrong field types. 
Distinguish an absent `params` key from a present value of the wrong type and 
report the entry number.



-- 
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