fix(engine): clarify error message for invalid append

Signed-off-by: Luca Guerra <luca@guerra.sh>
This commit is contained in:
Luca Guerra
2023-12-22 16:56:44 +00:00
committed by poiana
parent 04dd06b2c6
commit 728c8d7d0e
2 changed files with 2 additions and 3 deletions

View File

@@ -258,7 +258,7 @@ TEST_F(engine_loader_test, rule_incorrect_override_type)
std::string rule_name = "failing_rule"; std::string rule_name = "failing_rule";
ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
ASSERT_EQ(m_load_result_json["errors"][0]["message"], "Key 'priority' cannot be appended to"); ASSERT_EQ(m_load_result_json["errors"][0]["message"], "Key 'priority' cannot be appended to, use 'replace' instead");
ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["context"]["snippet"]).find("priority: append") != std::string::npos); ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["context"]["snippet"]).find("priority: append") != std::string::npos);
} }
@@ -300,7 +300,6 @@ TEST_F(engine_loader_test, rule_override_without_rule)
std::string rule_name = "failing_rule"; std::string rule_name = "failing_rule";
ASSERT_FALSE(load_rules(rules_content, "rules.yaml")); ASSERT_FALSE(load_rules(rules_content, "rules.yaml"));
// std::cout << m_load_result_json.dump(4) << std::endl;
ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("no rule by that name already exists") != std::string::npos); ASSERT_TRUE(std::string(m_load_result_json["errors"][0]["message"]).find("no rule by that name already exists") != std::string::npos);
} }

View File

@@ -161,7 +161,7 @@ static void decode_overrides(const YAML::Node& item,
if (operation == "append") if (operation == "append")
{ {
rule_loader::context keyctx(it->first, rule_loader::context::OVERRIDE, key, overridectx); rule_loader::context keyctx(it->first, rule_loader::context::OVERRIDE, key, overridectx);
THROW(!is_overridable_append, std::string("Key '") + key + std::string("' cannot be appended to"), keyctx); THROW(!is_overridable_append, std::string("Key '") + key + std::string("' cannot be appended to, use 'replace' instead"), keyctx);
out_append.insert(key); out_append.insert(key);
} }