Better input framework error messages for unset non-optionals

The input framework currently gives a rather opaque error message when
encountering a line in which a required value is not provided. This
change updates this behavior; the error message now provides the record
element (or the name or the index element) which was not set in the
input data, even though it is required to be set by the underlying Zeek
type.
This commit is contained in:
Johanna Amann 2023-07-21 15:11:31 +01:00
parent 0e40f7e6af
commit 33d6e1a011
6 changed files with 100 additions and 8 deletions

View file

@ -1104,9 +1104,10 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType*
const char* warning = "Skipping input with missing non-optional value"; const char* warning = "Skipping input with missing non-optional value";
if ( source && file_pos != -1 ) if ( source && file_pos != -1 )
Warning(i, "%s:%d: %s", source, file_pos, warning); Warning(i, "%s:%d: %s (index field %s)", source, file_pos, warning,
type->FieldName(j));
else else
Warning(i, "%s", warning); Warning(i, "%s (index field %s)", warning, type->FieldName(j));
have_error = true; have_error = true;
} }
@ -1961,9 +1962,10 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const* v
const char* warning = "Skipping input with missing non-optional value"; const char* warning = "Skipping input with missing non-optional value";
if ( source && file_pos != -1 ) if ( source && file_pos != -1 )
Warning(stream, "%s:%d: %s", source, file_pos, warning); Warning(stream, "%s:%d: %s (record field %s)", source, file_pos, warning,
request_type->FieldName(i));
else else
Warning(stream, "%s", warning); Warning(stream, "%s (record field %s)", warning, request_type->FieldName(i));
have_error = true; have_error = true;
} }

View file

@ -1,9 +1,9 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning: ../input.log:3: Skipping input with missing non-optional value warning: ../input.log:3: Skipping input with missing non-optional value (record field s)
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Invalid value for subnet: 127.0.0.1 warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Invalid value for subnet: 127.0.0.1
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Error while reading set or vector warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Error while reading set or vector
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line. warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line.
warning: ../input.log:3: Skipping input with missing non-optional value warning: ../input.log:3: Skipping input with missing non-optional value (record field s)
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Invalid value for subnet: 127.0.0.1 warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Invalid value for subnet: 127.0.0.1
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Error while reading set or vector warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Error while reading set or vector
warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line. warning: ..<...>/Input::READER_ASCII: ../input.log, line 4: Could not convert line 'name 127.0.0.1' of ../input.log to Val. Ignoring line.

View file

@ -1,11 +1,11 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
### NOTE: This file has been sorted with diff-sort. ### NOTE: This file has been sorted with diff-sort.
EventErrorEvent, ../input.log:3: Skipping input with missing non-optional value, Reporter::WARNING EventErrorEvent, ../input.log:3: Skipping input with missing non-optional value (record field s), Reporter::WARNING
EventErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING EventErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING
EventErrorEvent, Error while reading set or vector, Reporter::WARNING EventErrorEvent, Error while reading set or vector, Reporter::WARNING
EventErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING EventErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING
TableErrorEvent, ../input.log:3: Skipping input with missing non-optional value, Reporter::WARNING TableErrorEvent, ../input.log:3: Skipping input with missing non-optional value (record field s), Reporter::WARNING
TableErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING TableErrorEvent, Could not convert line 'name\x09127.0.0.1' of ../input.log to Val. Ignoring line., Reporter::WARNING
TableErrorEvent, Error while reading set or vector, Reporter::WARNING TableErrorEvent, Error while reading set or vector, Reporter::WARNING
TableErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING TableErrorEvent, Invalid value for subnet: 127.0.0.1, Reporter::WARNING

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning: ../input.log:3: Skipping input with missing non-optional value (index field y)
received termination signal
>>>

View file

@ -0,0 +1,14 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
### NOTE: This file has been sorted with diff-sort.
127.0.0.1
127.0.0.1
127.0.0.1
Event, [s={
Event, [s={
TableErrorEvent, ../input.log:3: Skipping input with missing non-optional value (index field y), Reporter::WARNING
[name, name2] = [s={
{
}
}]
}]
}]

View file

@ -0,0 +1,72 @@
# @TEST-EXEC: btest-bg-run zeek zeek -b %INPUT
# @TEST-EXEC: btest-bg-wait 10
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff out
# @TEST-EXEC: sed 1d .stderr > .stderrwithoutfirstline
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderrwithoutfirstline
@TEST-START-FILE input.log
#separator \x09
#fields i y s
name - 127.0.0.1
name name2 127.0.0.1
@TEST-END-FILE
redef exit_only_after_terminate = T;
redef InputAscii::fail_on_invalid_lines = T;
global outfile: file;
module A;
type Idx: record {
i: string;
y: string;
};
type Val: record {
s: set[addr];
};
global endcount: count = 0;
global servers: table[string, string] of Val = table();
event handle_our_errors(desc: Input::TableDescription, msg: string, level: Reporter::Level)
{
print outfile, "TableErrorEvent", msg, level;
}
event handle_our_errors_event(desc: Input::EventDescription, msg: string, level: Reporter::Level)
{
print outfile, "EventErrorEvent", msg, level;
}
event line(description: Input::EventDescription, tpe: Input::Event, v: Val)
{
print outfile, "Event", v;
}
event zeek_init()
{
outfile = open("../out");
# first read in the old stuff into the table...
Input::add_table([$source="../input.log", $name="ssh", $error_ev=handle_our_errors, $idx=Idx, $val=Val, $destination=servers]);
}
event Input::end_of_data(name: string, source:string)
{
++endcount;
# ... and when we're done, move to reading via events.
# This makes the reads sequential, avoiding races in the output.
if ( endcount == 1 )
{
Input::add_event([$source="../input.log", $name="sshevent", $error_ev=handle_our_errors_event, $fields=Val, $want_record=T, $ev=line]);
}
if ( endcount == 2 )
{
print outfile, servers;
terminate();
}
}