mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Stmt: Rework assertion hooks break semantics
Using break in either of the hooks allows to suppress the default reporter error message rather than suppressing solely based on the existence of an assertion_failure() handler.
This commit is contained in:
parent
25ea678626
commit
0b0f6e509f
9 changed files with 40 additions and 26 deletions
14
src/Stmt.cc
14
src/Stmt.cc
|
@ -1928,16 +1928,22 @@ ValPtr AssertStmt::Exec(Frame* f, StmtFlowType& flow)
|
|||
bt->Insert(0, assert_elem);
|
||||
}
|
||||
|
||||
// Breaking from either the assertion_failure() or assertion_result()
|
||||
// hook can be used to suppress the default log message.
|
||||
bool report_error = true;
|
||||
|
||||
if ( run_result_hook )
|
||||
assertion_result_hook->Invoke(zeek::val_mgr->Bool(assert_result), cond_val, msg_val, bt);
|
||||
report_error &= assertion_result_hook
|
||||
->Invoke(zeek::val_mgr->Bool(assert_result), cond_val, msg_val, bt)
|
||||
->AsBool();
|
||||
|
||||
if ( assert_result )
|
||||
return Val::nil;
|
||||
|
||||
// Run the installed failure hooks, or log a default message.
|
||||
if ( run_failure_hook )
|
||||
assertion_failure_hook->Invoke(cond_val, msg_val, bt);
|
||||
else
|
||||
report_error &= assertion_failure_hook->Invoke(cond_val, msg_val, bt)->AsBool();
|
||||
|
||||
if ( report_error )
|
||||
{
|
||||
std::string reporter_msg = util::fmt("assertion failure: %s", cond_val->CheckString());
|
||||
if ( msg_val->Len() > 0 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue