input: Add location info for invalid enums

Fixes #2613
This commit is contained in:
Arne Welzel 2022-11-29 12:12:55 +01:00
parent 0e97c29eb8
commit e5d9a715ce
4 changed files with 15 additions and 3 deletions

View file

@ -2417,8 +2417,16 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, Type* request_type,
zeek_int_t index = request_type->AsEnumType()->Lookup(module, var.c_str());
if ( index == -1 )
{
Warning(i, "Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(),
i->name.c_str());
auto source = i->reader->Info().source;
auto file_pos = val->GetFileLineNumber();
const char* warning = zeek::util::fmt(
"Value '%s' for stream '%s' is not a valid enum.", enum_string.c_str(),
i->name.c_str());
if ( source && file_pos != -1 )
Warning(i, "%s, line %d: %s", source, file_pos, warning);
else
Warning(i, "%s", warning);
have_error = true;
return nullptr;