mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-13 13:32:50 +00:00
cleanup: use macros for default error messages
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
This commit is contained in:
@@ -190,10 +190,7 @@ void rule_loader::collector::define(configuration& cfg, list_info& info)
|
||||
void rule_loader::collector::append(configuration& cfg, list_info& info)
|
||||
{
|
||||
auto prev = m_list_infos.at(info.name);
|
||||
THROW(!prev,
|
||||
// "List has 'append' key or an append override but no list by that name already exists", // TODO update this error and update testing
|
||||
"List has 'append' key but no list by that name already exists",
|
||||
info.ctx);
|
||||
THROW(!prev, ERROR_NO_PREVIOUS_LIST, info.ctx);
|
||||
prev->items.insert(prev->items.end(), info.items.begin(), info.items.end());
|
||||
append_info(prev, info, m_cur_index++);
|
||||
}
|
||||
@@ -206,9 +203,7 @@ void rule_loader::collector::define(configuration& cfg, macro_info& info)
|
||||
void rule_loader::collector::append(configuration& cfg, macro_info& info)
|
||||
{
|
||||
auto prev = m_macro_infos.at(info.name);
|
||||
THROW(!prev,
|
||||
"Macro has 'append' key but no macro by that name already exists",
|
||||
info.ctx);
|
||||
THROW(!prev, ERROR_NO_PREVIOUS_MACRO, info.ctx);
|
||||
prev->cond += " ";
|
||||
prev->cond += info.cond;
|
||||
append_info(prev, info, m_cur_index++);
|
||||
@@ -244,10 +239,7 @@ void rule_loader::collector::append(configuration& cfg, rule_update_info& info)
|
||||
{
|
||||
auto prev = m_rule_infos.at(info.name);
|
||||
|
||||
THROW(!prev,
|
||||
// "Rule has 'append' key or an append override but no rule by that name already exists", // TODO replace with this and update testing
|
||||
"Rule has 'append' key but no rule by that name already exists",
|
||||
info.ctx);
|
||||
THROW(!prev, ERROR_NO_PREVIOUS_RULE, info.ctx);
|
||||
THROW(!info.has_any_value(),
|
||||
"Appended rule must have exceptions or condition property",
|
||||
// "Appended rule must have at least one field that can be appended to", // TODO replace with this and update testing
|
||||
|
@@ -22,6 +22,7 @@ limitations under the License.
|
||||
|
||||
#include "rule_loader_reader.h"
|
||||
#include "falco_engine_version.h"
|
||||
#include "rule_loading_messages.h"
|
||||
|
||||
#define THROW(cond, err, ctx) { if ((cond)) { throw rule_loader::rule_load_exception(falco::load_result::LOAD_ERR_YAML_VALIDATE, (err), (ctx)); } }
|
||||
|
||||
|
@@ -23,15 +23,6 @@ limitations under the License.
|
||||
#include "version.h"
|
||||
#include "falco_engine_version.h"
|
||||
|
||||
// Error message used when both 'override' and 'append' are specified.
|
||||
#define OVERRIDE_APPEND_ERROR_MESSAGE "Keys 'override' and 'append: true' cannot be used together. Add an 'append' entry (e.g. 'condition: append') under 'override' instead."
|
||||
|
||||
// Warning message used when `append` is used.
|
||||
#define WARNING_APPEND_MESSAGE "'append' key is deprecated. Add an 'append' entry (e.g. 'condition: append') under 'override' instead."
|
||||
|
||||
// Warning message used when `enabled` is used without override.
|
||||
#define WARNING_ENABLED_MESSAGE "The standalone 'enabled' key usage is deprecated. The correct approach requires also a 'replace' entry under the 'override' key (i.e. 'enabled: replace')."
|
||||
|
||||
namespace rule_loader
|
||||
{
|
||||
|
||||
|
16
userspace/engine/rule_loading_messages.h
Normal file
16
userspace/engine/rule_loading_messages.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
// Error message used when both 'override' and 'append' keys are specified.
|
||||
#define OVERRIDE_APPEND_ERROR_MESSAGE "Keys 'override' and 'append: true' cannot be used together. Add an 'append' entry (e.g. 'condition: append') under 'override' instead."
|
||||
|
||||
// Warning message used when 'append' key is used.
|
||||
#define WARNING_APPEND_MESSAGE "'append' key is deprecated. Add an 'append' entry (e.g. 'condition: append') under 'override' instead."
|
||||
|
||||
// Warning message used when 'enabled' is used without 'override' key.
|
||||
#define WARNING_ENABLED_MESSAGE "The standalone 'enabled' key usage is deprecated. The correct approach requires also a 'replace' entry under the 'override' key (i.e. 'enabled: replace')."
|
||||
|
||||
#define ERROR_NO_PREVIOUS_MACRO "Macro uses 'append' or 'override.condition: append' but no macro by that name already exists"
|
||||
|
||||
#define ERROR_NO_PREVIOUS_LIST "List uses 'append' or 'override.items: append' but no list by that name already exists"
|
||||
|
||||
#define ERROR_NO_PREVIOUS_RULE "Rule uses 'append' or 'override.<key>: append' but no rule by that name already exists"
|
Reference in New Issue
Block a user