new(engine): raise warning instead of error on invalid macro/list name

Signed-off-by: Gianmatteo Palmieri <mail@gian.im>
This commit is contained in:
Gianmatteo Palmieri
2024-04-15 14:48:49 +02:00
committed by poiana
parent e21a3a5e58
commit dd59c48034
4 changed files with 20 additions and 10 deletions

View File

@@ -73,7 +73,9 @@ static const std::string warning_codes[] = {
"LOAD_DEPRECATED_ITEM",
"LOAD_WARNING_EXTENSION",
"LOAD_APPEND_NO_VALUES",
"LOAD_EXCEPTION_NAME_NOT_UNIQUE"
"LOAD_EXCEPTION_NAME_NOT_UNIQUE",
"LOAD_INVALID_MACRO_NAME",
"LOAD_INVALID_LIST_NAME"
};
const std::string& falco::load_result::warning_code_str(warning_code wc)
@@ -92,7 +94,9 @@ static const std::string warning_strings[] = {
"Used deprecated item",
"Warning in extension item",
"Overriding/appending with no values",
"Multiple exceptions defined with the same name"
"Multiple exceptions defined with the same name",
"Invalid macro name",
"Invalid list name"
};
const std::string& falco::load_result::warning_str(warning_code wc)
@@ -111,7 +115,9 @@ static const std::string warning_descs[] = {
"A deprecated item is employed by lists, macros, or rules.",
"An extension item has a warning",
"A rule exception is overriding/appending with no values",
"A rule is defining multiple exceptions with the same name"
"A rule is defining multiple exceptions with the same name",
"A macro is defined with an invalid name",
"A list is defined with an invalid name"
};
const std::string& falco::load_result::warning_desc(warning_code wc)

View File

@@ -59,7 +59,9 @@ public:
LOAD_DEPRECATED_ITEM,
LOAD_WARNING_EXTENSION,
LOAD_APPEND_NO_VALUES,
LOAD_EXCEPTION_NAME_NOT_UNIQUE
LOAD_EXCEPTION_NAME_NOT_UNIQUE,
LOAD_INVALID_MACRO_NAME,
LOAD_INVALID_LIST_NAME
};
virtual ~load_result() = default;

View File

@@ -471,7 +471,10 @@ void rule_loader::reader::read_item(
rule_loader::context ctx(item, rule_loader::context::LIST, name, parent);
bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_barestr);
THROW(invalid_name, ERROR_INVALID_LIST_NAME RGX_BARESTR, ctx);
if(invalid_name)
{
cfg.res->add_warning(falco::load_result::LOAD_INVALID_LIST_NAME, "List has an invalid name. List names must match a regular expression: " RGX_BARESTR, ctx);
}
rule_loader::list_info v(ctx);
@@ -515,7 +518,10 @@ void rule_loader::reader::read_item(
rule_loader::context ctx(item, rule_loader::context::MACRO, name, parent);
bool invalid_name = !re2::RE2::FullMatch(name, s_rgx_identifier);
THROW(invalid_name, ERROR_INVALID_MACRO_NAME RGX_IDENTIFIER, ctx);
if(invalid_name)
{
cfg.res->add_warning(falco::load_result::LOAD_INVALID_MACRO_NAME, "Macro has an invalid name. Macro names must match a regular expression: " RGX_IDENTIFIER, ctx);
}
rule_loader::macro_info v(ctx);
v.name = name;

View File

@@ -21,7 +21,3 @@
#define ERROR_NO_PREVIOUS_RULE_APPEND "Rule uses 'append' or 'override.<key>: append' but no rule by that name already exists"
#define ERROR_NO_PREVIOUS_RULE_REPLACE "An 'override.<key>: replace' to a rule was requested but no rule by that name already exists"
#define ERROR_INVALID_MACRO_NAME "Macro has an invalid name. Macro names must match a regular expression: "
#define ERROR_INVALID_LIST_NAME "List has an invalid name. List names must match a regular expression: "