]> granicus.if.org Git - icinga2/commitdiff
Improve error logging for match/regex/cidr_match functions and unsupported dictionary...
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 27 Jul 2018 14:34:50 +0000 (16:34 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 13 Sep 2018 11:00:40 +0000 (13:00 +0200)
fixes #6442
refs #6497

lib/base/scriptutils.cpp

index f8ab8ce00005c3e631857f92c996997ec74eca3c..3c1a4e5a59638a18e143018e59715263a5e66cbc 100644 (file)
@@ -108,10 +108,14 @@ bool ScriptUtils::CastBool(const Value& value)
 bool ScriptUtils::Regex(const std::vector<Value>& args)
 {
        if (args.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Regular expression and text must be specified."));
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Regular expression and text must be specified for regex()."));
 
        String pattern = args[0];
        const Value& argTexts = args[1];
+
+       if (argTexts.IsObjectType<Dictionary>())
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionaries are not supported by regex()."));
+
        MatchType mode;
 
        if (args.size() > 2)
@@ -159,10 +163,14 @@ bool ScriptUtils::Regex(const std::vector<Value>& args)
 bool ScriptUtils::Match(const std::vector<Value>& args)
 {
        if (args.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("Pattern and text must be specified."));
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Pattern and text must be specified for match()."));
 
        String pattern = args[0];
        const Value& argTexts = args[1];
+
+       if (argTexts.IsObjectType<Dictionary>())
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionaries are not supported by match()."));
+
        MatchType mode;
 
        if (args.size() > 2)
@@ -201,10 +209,14 @@ bool ScriptUtils::Match(const std::vector<Value>& args)
 bool ScriptUtils::CidrMatch(const std::vector<Value>& args)
 {
        if (args.size() < 2)
-               BOOST_THROW_EXCEPTION(std::invalid_argument("CIDR and IP address must be specified."));
+               BOOST_THROW_EXCEPTION(std::invalid_argument("CIDR and IP address must be specified for cidr_match()."));
 
        String pattern = args[0];
        const Value& argIps = args[1];
+
+       if (argIps.IsObjectType<Dictionary>())
+               BOOST_THROW_EXCEPTION(std::invalid_argument("Dictionaries are not supported by cidr_match()."));
+
        MatchType mode;
 
        if (args.size() > 2)