]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Better handling of non-existent Lua function name in YAML
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Mar 2025 15:37:58 +0000 (16:37 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 24 Mar 2025 15:39:51 +0000 (16:39 +0100)
This commit changes the way DNSdist handles a non-existent Lua function
name being referenced from the YAML configuration: instead of silently
ignoring the problem, it loudly complains before exiting.

pdns/dnsdistdist/dnsdist-configuration-yaml.cc

index 00d2c5aa1d120c829e3529f7b87c43357f3f1a1d..a707ec419a374296e6d2484f5d3a28a907544925 100644 (file)
@@ -144,7 +144,11 @@ template <class FuncType>
 static bool getLuaFunctionFromConfiguration(FuncType& destination, const ::rust::string& functionName, const ::rust::string& functionCode, const ::rust::string& functionFile, const std::string& context)
 {
   if (!functionName.empty()) {
-    return getOptionalLuaFunction<FuncType>(destination, functionName);
+    auto found = getOptionalLuaFunction<FuncType>(destination, functionName);
+    if (found) {
+      return true;
+    }
+    throw std::runtime_error("Unable to locate the Lua function named '" + std::string(functionName) + "', referenced by a lua directive in " + context + " context");
   }
   if (!functionCode.empty()) {
     auto function = dnsdist::lua::getFunctionFromLuaCode<FuncType>(std::string(functionCode), context);