From aa9242913fbe26a7c29218921ce99f06a6b7499c Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Fri, 8 Jan 2021 19:23:37 -0800 Subject: [PATCH] More precise type information in a config framework error message When an option's value is a reader-incompatible table or set, Zeek now renders the type as expressed in the script layer (e.g. "set[addr,addr]") as opposed to the internal type tag (which'd here be "table", including for sets). --- src/input/readers/config/Config.cc | 9 ++++++--- src/input/readers/config/Config.h | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 0a3d33811c..ec6226de99 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -10,6 +10,7 @@ #include #include +#include "zeek/Desc.h" #include "zeek/input/Manager.h" #include "zeek/threading/SerialTypes.h" @@ -38,7 +39,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) if ( id->GetType()->Tag() == TYPE_RECORD || ! Manager::IsCompatibleType(id->GetType().get()) ) { - option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag()); + option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag(), id); continue; } @@ -49,7 +50,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) else if ( primary == TYPE_VECTOR ) secondary = id->GetType()->AsVectorType()->Yield()->Tag(); - option_types[id->Name()] = std::make_tuple(primary, secondary); + option_types[id->Name()] = std::make_tuple(primary, secondary, id); } } @@ -212,8 +213,10 @@ bool Config::DoUpdate() if ( std::get<0>((*typeit).second) == TYPE_ERROR ) { + ODesc d; + std::get<2>((*typeit).second)->GetType()->Describe(&d); Warning(Fmt("Option '%s' has type '%s', which is not supported for file input. Ignoring line.", - key.c_str(), type_name(std::get<1>((*typeit).second)))); + key.c_str(), d.Description())); continue; } diff --git a/src/input/readers/config/Config.h b/src/input/readers/config/Config.h index c8e8360ccd..fe525c66ad 100644 --- a/src/input/readers/config/Config.h +++ b/src/input/readers/config/Config.h @@ -9,6 +9,7 @@ #include #include +#include "zeek/ID.h" #include "zeek/input/ReaderBackend.h" #include "zeek/threading/formatters/Ascii.h" @@ -50,7 +51,7 @@ private: std::string empty_field; std::unique_ptr formatter; - std::unordered_map> option_types; + std::unordered_map> option_types; std::unordered_map option_values; };