From 83910be726d2fe03cfd0f5d09d87cde61254c0da Mon Sep 17 00:00:00 2001 From: Gianmatteo Palmieri Date: Tue, 9 Apr 2024 13:24:56 +0200 Subject: [PATCH] new(engine): raise warning instead of error on not-unique exceptions names Signed-off-by: Gianmatteo Palmieri --- userspace/engine/falco_load_result.cpp | 9 ++++++--- userspace/engine/falco_load_result.h | 3 ++- userspace/engine/rule_loader_reader.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/userspace/engine/falco_load_result.cpp b/userspace/engine/falco_load_result.cpp index 10790aca..76c859c8 100644 --- a/userspace/engine/falco_load_result.cpp +++ b/userspace/engine/falco_load_result.cpp @@ -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) @@ -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) @@ -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) diff --git a/userspace/engine/falco_load_result.h b/userspace/engine/falco_load_result.h index dd707c7e..79db7349 100644 --- a/userspace/engine/falco_load_result.h +++ b/userspace/engine/falco_load_result.h @@ -58,7 +58,8 @@ public: 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; diff --git a/userspace/engine/rule_loader_reader.cpp b/userspace/engine/rule_loader_reader.cpp index e4c2c9a7..df32715d 100644 --- a/userspace/engine/rule_loader_reader.cpp +++ b/userspace/engine/rule_loader_reader.cpp @@ -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