Skip to content

Commit

Permalink
new(engine): raise warning instead of error on not-unique exceptions …
Browse files Browse the repository at this point in the history
…names

Signed-off-by: Gianmatteo Palmieri <[email protected]>
  • Loading branch information
mrgian authored and poiana committed Apr 11, 2024
1 parent 7ac5c36 commit 83910be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions userspace/engine/falco_load_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ static const std::string warning_codes[] = {
"LOAD_UNKNOWN_ITEM",
"LOAD_DEPRECATED_ITEM",
"LOAD_WARNING_EXTENSION",
"LOAD_APPEND_NO_VALUES"
"LOAD_APPEND_NO_VALUES",
"LOAD_EXCEPTION_NAME_NOT_UNIQUE"
};

const std::string& falco::load_result::warning_code_str(warning_code wc)
Expand All @@ -90,7 +91,8 @@ static const std::string warning_strings[] = {
"Unknown rules file item",
"Used deprecated item",
"Warning in extension item",
"Overriding/appending with no values"
"Overriding/appending with no values",
"Multiple exceptions defined with the same name"
};

const std::string& falco::load_result::warning_str(warning_code wc)
Expand All @@ -108,7 +110,8 @@ static const std::string warning_descs[] = {
"An unknown top-level object is in the rules content. It will be ignored.",
"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 exception is overriding/appending with no values",
"A rule is defining multiple exceptions with the same name"
};

const std::string& falco::load_result::warning_desc(warning_code wc)
Expand Down
3 changes: 2 additions & 1 deletion userspace/engine/falco_load_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class load_result {
LOAD_UNKNOWN_ITEM,
LOAD_DEPRECATED_ITEM,
LOAD_WARNING_EXTENSION,
LOAD_APPEND_NO_VALUES
LOAD_APPEND_NO_VALUES,
LOAD_EXCEPTION_NAME_NOT_UNIQUE
};

virtual ~load_result() = default;
Expand Down
6 changes: 4 additions & 2 deletions userspace/engine/rule_loader_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ static void read_rule_exceptions(
// Check if an exception with the same name has already been defined
for (auto &exception : exceptions)
{
THROW((v_ex.name == exception.name),
"Exceptions names in the same object must be unique", ex_ctx);
if(v_ex.name == exception.name)
{
cfg.res->add_warning(falco::load_result::LOAD_EXCEPTION_NAME_NOT_UNIQUE, "Multiple definitions of exception '" + v_ex.name + "' in the same rule", ex_ctx);
}
}

// note: the legacy lua loader used to throw a "xxx must strings" error
Expand Down

0 comments on commit 83910be

Please sign in to comment.