Report suppressed warnings count

This also triggers if there is one warning, which seems a little weird,
but it seems mostly reasonable.
This commit is contained in:
Evan Typanski 2024-09-27 13:20:17 -04:00
parent 6e8d43a552
commit ecabf882ac
4 changed files with 17 additions and 8 deletions

View file

@ -250,22 +250,28 @@ void ReaderBackend::Info(const char* msg) {
MsgThread::Info(msg);
}
void ReaderBackend::StopWarningSuppression() {
suppress_warnings = false;
if ( warnings_suppressed > 0 )
Warning(Fmt("Suppressed %zu warning(s)", warnings_suppressed));
warnings_suppressed = 0;
}
void ReaderBackend::FailWarn(bool is_error, const char* msg, bool suppress_future) {
if ( is_error )
Error(msg);
else {
// suppress error message when we are already in error mode.
// There is no reason to repeat it every second.
if ( ! suppress_warnings )
Warning(msg);
Warning(msg);
if ( suppress_future )
suppress_warnings = true;
}
}
void ReaderBackend::Warning(const char* msg) {
if ( suppress_warnings )
if ( suppress_warnings ) {
warnings_suppressed++;
return;
}
SendOut(new ReaderErrorMessage(frontend, ReaderErrorMessage::WARNING, msg));
MsgThread::Warning(msg);

View file

@ -203,7 +203,7 @@ public:
*/
void FailWarn(bool is_error, const char* msg, bool suppress_future = false);
inline void StopWarningSuppression() { suppress_warnings = false; };
void StopWarningSuppression();
// Overridden from MsgThread.
bool OnHeartbeat(double network_time, double current_time) override;
@ -365,6 +365,7 @@ private:
// this is an internal indicator in case the read is currently in a failed state
// it's used to suppress duplicate error messages.
bool suppress_warnings = false;
size_t warnings_suppressed = 0;
};
} // namespace zeek::input

View file

@ -139,14 +139,14 @@ bool Ascii::OpenFile() {
if ( ! file.is_open() ) {
FailWarn(fail_on_file_problem, Fmt("Init: cannot open %s", fname.c_str()), true);
return ! fail_on_file_problem;
return false;
}
if ( ReadHeader(false) == false ) {
FailWarn(fail_on_file_problem, Fmt("Init: cannot open %s; problem reading file header", fname.c_str()), true);
file.close();
return ! fail_on_file_problem;
return false;
}
if ( ! read_location ) {

View file

@ -1,5 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning: ..<...>/Input::READER_ASCII: ../input.log, line 3: Not enough fields in line 'hello' of ../input.log. Found 0 fields, want positions 1 and -1
warning: ..<...>/Input::READER_ASCII: ../input.log, line 9: Suppressed 5 warning(s)
warning: ..<...>/Input::READER_ASCII: ../input.log, line 10: Not enough fields in line 'hello' of ../input.log. Found 0 fields, want positions 1 and -1
warning: ..<...>/Input::READER_ASCII: ../input.log, line 16: Suppressed 6 warning(s)
received termination signal
>>>