...and another small change to error handling -> now errors in single lines

do not kill processing, but simply ignore the line, log it, and continue.
This commit is contained in:
Bernhard Amann 2012-08-27 11:38:20 -07:00
parent 5c486dae7e
commit 56fa56ffa9
4 changed files with 32 additions and 20 deletions

View file

@ -228,7 +228,7 @@ bool Ascii::CheckNumberError(const string & s, const char * end)
}
if ( endnotnull )
Error(Fmt("Number '%s' contained non-numeric trailing characters. Ignored trailing characters '%s'", s.c_str(), end));
Warning(Fmt("Number '%s' contained non-numeric trailing characters. Ignored trailing characters '%s'", s.c_str(), end));
if ( errno == EINVAL )
{
@ -236,7 +236,10 @@ bool Ascii::CheckNumberError(const string & s, const char * end)
return true;
}
else if ( errno == ERANGE )
Error(Fmt("Number '%s' out of supported range. Number was truncated", s.c_str()));
{
Error(Fmt("Number '%s' out of supported range.", s.c_str()));
return true;
}
return false;
}
@ -492,6 +495,7 @@ bool Ascii::DoUpdate()
while ( GetLine(line ) )
{
// split on tabs
bool error = false;
istringstream splitstream(line);
map<int, string> stringfields;
@ -537,8 +541,9 @@ bool Ascii::DoUpdate()
Value* val = EntryToVal(stringfields[(*fit).position], *fit);
if ( val == 0 )
{
Error(Fmt("Could not convert line '%s' to Val. Aborting file read.", line.c_str()));
return false;
Error(Fmt("Could not convert line '%s' to Val. Ignoring line.", line.c_str()));
error = true;
break;
}
if ( (*fit).secondary_position != -1 )
@ -555,6 +560,21 @@ bool Ascii::DoUpdate()
fpos++;
}
if ( error )
{
// encountered non-fatal error. ignoring line.
// first - delete all successfully read fields and the array structure.
for ( int i = 0; i < fpos; i++ )
delete fields[fpos];
delete[] fields;
continue;
}
//printf("fpos: %d, second.num_fields: %d\n", fpos, (*it).second.num_fields);
assert ( fpos == NumFields() );

View file

@ -1,8 +1,8 @@
error: ../input.log/Input::READER_ASCII: Number '12129223372036854775800' out of supported range. Number was truncated
error: ../input.log/Input::READER_ASCII: Number '121218446744073709551612' out of supported range. Number was truncated
error: ../input.log/Input::READER_ASCII: Number '9223372036854775801TEXTHERE' contained non-numeric trailing characters. Ignored trailing characters 'TEXTHERE'
error: ../input.log/Input::READER_ASCII: Number '1Justtext' contained non-numeric trailing characters. Ignored trailing characters 'Justtext'
error: ../input2.log/Input::READER_ASCII: String 'Justtext' contained no parseable number
error: ../input2.log/Input::READER_ASCII: Could not convert line 'Justtext 1' to Val. Aborting file read.
error: ../input.log/Input::READER_ASCII: Number '12129223372036854775800' out of supported range.
error: ../input.log/Input::READER_ASCII: Could not convert line '12129223372036854775800 121218446744073709551612' to Val. Ignoring line.
warning: ../input.log/Input::READER_ASCII: Number '9223372036854775801TEXTHERE' contained non-numeric trailing characters. Ignored trailing characters 'TEXTHERE'
warning: ../input.log/Input::READER_ASCII: Number '1Justtext' contained non-numeric trailing characters. Ignored trailing characters 'Justtext'
error: ../input.log/Input::READER_ASCII: String 'Justtext' contained no parseable number
error: ../input.log/Input::READER_ASCII: Could not convert line 'Justtext 1' to Val. Ignoring line.
received termination signal
>>>

View file

@ -1,5 +1,4 @@
{
[9223372036854775807] = [c=18446744073709551615],
[9223372036854775800] = [c=4],
[9223372036854775801] = [c=1]
}

View file

@ -13,17 +13,10 @@
#types int count
12129223372036854775800 121218446744073709551612
9223372036854775801TEXTHERE 1Justtext
Justtext 1
9223372036854775800 -18446744073709551612
@TEST-END-FILE
@TEST-START-FILE input2.log
#separator \x09
#fields i c
#types int count
Justtext 1
@TEST-END-FILE
@load frameworks/communication/listen
global outfile: file;
@ -51,5 +44,5 @@ event bro_init()
event Input::update_finished(name: string, source:string)
{
print outfile, servers;
Input::add_table([$source="../input2.log", $name="ssh2", $idx=Idx, $val=Val, $destination=servers]);
terminate();
}