diff --git a/userspace/engine/rule_loader.cpp b/userspace/engine/rule_loader.cpp index 66a5acec..9ceb39a3 100644 --- a/userspace/engine/rule_loader.cpp +++ b/userspace/engine/rule_loader.cpp @@ -64,6 +64,11 @@ rule_loader::context::context(const YAML::Node &item, init(parent.name(), position(item.Mark()), item_type, item_name, parent); } +rule_loader::context::context(const YAML::Mark &mark, const context& parent) +{ + init(parent.name(), position(mark), item_type::VALUE_FOR, "", parent); +} + rule_loader::context::context(const libsinsp::filter::ast::pos_info& pos, const std::string& condition, const context& parent) diff --git a/userspace/engine/rule_loader.h b/userspace/engine/rule_loader.h index 6b69c35b..c0c30522 100644 --- a/userspace/engine/rule_loader.h +++ b/userspace/engine/rule_loader.h @@ -113,6 +113,9 @@ namespace rule_loader item_type item_type, const std::string& item_name, const context& parent); + context( + const YAML::Mark &mark, + const context& parent); // Build a context from a condition expression + // parser position. This does not use the original diff --git a/userspace/engine/rule_loader_reader.cpp b/userspace/engine/rule_loader_reader.cpp index fa2fd3a9..fcbd16df 100644 --- a/userspace/engine/rule_loader_reader.cpp +++ b/userspace/engine/rule_loader_reader.cpp @@ -437,23 +437,32 @@ static void read_item( bool rule_loader::reader::read(rule_loader::configuration& cfg, collector& collector) { std::vector docs; + rule_loader::context ctx(cfg.name); try { docs = YAML::LoadAll(cfg.content); } - catch(const exception& e) + catch (YAML::ParserException& e) + { + rule_loader::context ictx(e.mark, ctx); + cfg.res->add_error(falco::load_result::LOAD_ERR_YAML_PARSE, e.what(), ictx); + return false; + } + catch (std::exception& e) { - rule_loader::context ctx(cfg.name); cfg.res->add_error(falco::load_result::LOAD_ERR_YAML_PARSE, e.what(), ctx); return false; } + catch (...) + { + cfg.res->add_error(falco::load_result::LOAD_ERR_YAML_PARSE, "unknown YAML parsing error", ctx); + return false; + } for (auto doc = docs.begin(); doc != docs.end(); doc++) { if (doc->IsDefined() && !doc->IsNull()) { - rule_loader::context ctx(cfg.name); - try { THROW(!doc->IsMap() && !doc->IsSequence(), "Rules content is not yaml", @@ -479,7 +488,23 @@ bool rule_loader::reader::read(rule_loader::configuration& cfg, collector& colle // as it's effectively a new rules file, for // consistency we stop at the first error. return false; - }; + } + catch (YAML::ParserException& e) + { + rule_loader::context ictx(e.mark, ctx); + cfg.res->add_error(falco::load_result::LOAD_ERR_YAML_VALIDATE, e.what(), ictx); + return false; + } + catch (std::exception& e) + { + cfg.res->add_error(falco::load_result::LOAD_ERR_VALIDATE, e.what(), ctx); + return false; + } + catch (...) + { + cfg.res->add_error(falco::load_result::LOAD_ERR_VALIDATE, "unknown validation error", ctx); + return false; + } } }