From 00d66f1ac27d0e2d3c5d2aee0900ba2b4ad13344 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Mon, 19 Apr 2021 16:05:59 -0700 Subject: [PATCH] method for reporting run-time errors in compiled-to-C++ scripts --- src/Reporter.cc | 15 +++++++++++++++ src/Reporter.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/Reporter.cc b/src/Reporter.cc index 28ea5103a3..39d38dcee8 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -187,6 +187,21 @@ void Reporter::RuntimeError(const detail::Location* location, const char* fmt, . throw InterpreterException(); } +void Reporter::CPPRuntimeError(const char* fmt, ...) + { + ++errors; + va_list ap; + va_start(ap, fmt); + FILE* out = EmitToStderr(errors_to_stderr) ? stderr : nullptr; + DoLog("runtime error in compiled code", reporter_error, out, nullptr, nullptr, true, true, "", fmt, ap); + va_end(ap); + + if ( abort_on_scripting_errors ) + abort(); + + throw InterpreterException(); + } + void Reporter::InternalError(const char* fmt, ...) { va_list ap; diff --git a/src/Reporter.h b/src/Reporter.h index c76a5716f2..137f0f3a03 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -100,6 +100,10 @@ public: // function will not return but raise an InterpreterException. [[noreturn]] void RuntimeError(const detail::Location* location, const char* fmt, ...) __attribute__((format(printf, 3, 4))); + // Report a runtime error in executing a compiled script. This + // function will not return but raise an InterpreterException. + [[noreturn]] void CPPRuntimeError(const char* fmt, ...) __attribute__((format(printf, 2, 3))); + // Report a traffic weirdness, i.e., an unexpected protocol situation // that may lead to incorrectly processing a connnection. void Weird(const char* name, const char* addl = "", const char* source = ""); // Raises net_weird().