1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

bees: make exceptions less prominent in log output

Introduce a mechanism to suppress exceptions which do not produce a
full stack trace for common known cases where a loop should be aborted.
Use this mechanism to suppress the infamous "FIXME" exception.

Reduce the log level to at most NOTICE, and in some cases DEBUG.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2019-01-02 22:28:02 -05:00
parent 4a1971bce5
commit be2c55119e
3 changed files with 37 additions and 10 deletions

View File

@ -415,6 +415,7 @@ BeesResolver::replace_dst(const BeesFileRange &dst_bfr)
if (bbd.addr().get_physical_or_zero() == src_bbd.addr().get_physical_or_zero()) { if (bbd.addr().get_physical_or_zero() == src_bbd.addr().get_physical_or_zero()) {
BEESCOUNT(replacedst_same); BEESCOUNT(replacedst_same);
// stop looping here, all the other srcs will probably fail this test too // stop looping here, all the other srcs will probably fail this test too
BeesTracer::set_silent();
throw runtime_error("FIXME: bailing out here, need to fix this further up the call stack"); throw runtime_error("FIXME: bailing out here, need to fix this further up the call stack");
} }

View File

@ -78,41 +78,58 @@ do_cmd_help(char *argv[])
// tracing ---------------------------------------- // tracing ----------------------------------------
thread_local BeesTracer *BeesTracer::tl_next_tracer = nullptr; thread_local BeesTracer *BeesTracer::tl_next_tracer = nullptr;
thread_local bool BeesTracer::tl_silent = false;
BeesTracer::~BeesTracer() BeesTracer::~BeesTracer()
{ {
if (uncaught_exception()) { if (!tl_silent && uncaught_exception()) {
try { try {
m_func(); m_func();
} catch (exception &e) { } catch (exception &e) {
BEESLOGERR("Nested exception: " << e.what()); BEESLOGNOTICE("Nested exception: " << e.what());
} catch (...) { } catch (...) {
BEESLOGERR("Nested exception ..."); BEESLOGNOTICE("Nested exception ...");
} }
if (!m_next_tracer) { if (!m_next_tracer) {
BEESLOGERR("--- END TRACE --- exception ---"); BEESLOGNOTICE("--- END TRACE --- exception ---");
} }
} }
tl_next_tracer = m_next_tracer; tl_next_tracer = m_next_tracer;
if (!m_next_tracer) {
tl_silent = false;
}
} }
BeesTracer::BeesTracer(function<void()> f) : BeesTracer::BeesTracer(function<void()> f, bool silent) :
m_func(f) m_func(f)
{ {
m_next_tracer = tl_next_tracer; m_next_tracer = tl_next_tracer;
tl_next_tracer = this; tl_next_tracer = this;
tl_silent = silent;
} }
void void
BeesTracer::trace_now() BeesTracer::trace_now()
{ {
BeesTracer *tp = tl_next_tracer; BeesTracer *tp = tl_next_tracer;
BEESLOGERR("--- BEGIN TRACE ---"); BEESLOGNOTICE("--- BEGIN TRACE ---");
while (tp) { while (tp) {
tp->m_func(); tp->m_func();
tp = tp->m_next_tracer; tp = tp->m_next_tracer;
} }
BEESLOGERR("--- END TRACE ---"); BEESLOGNOTICE("--- END TRACE ---");
}
bool
BeesTracer::get_silent()
{
return tl_silent;
}
void
BeesTracer::set_silent()
{
tl_silent = true;
} }
thread_local BeesNote *BeesNote::tl_next = nullptr; thread_local BeesNote *BeesNote::tl_next = nullptr;
@ -721,8 +738,13 @@ int
bees_main(int argc, char *argv[]) bees_main(int argc, char *argv[])
{ {
set_catch_explainer([&](string s) { set_catch_explainer([&](string s) {
BEESLOGERR("\n\n*** EXCEPTION ***\n\t" << s << "\n***\n"); if (BeesTracer::get_silent()) {
BEESCOUNT(exception_caught); BEESLOGDEBUG("exception (ignored): " << s);
BEESCOUNT(exception_caught_silent);
} else {
BEESLOGNOTICE("\n\n*** EXCEPTION ***\n\t" << s << "\n***\n");
BEESCOUNT(exception_caught);
}
}); });
// The thread name for the main function is also what the kernel // The thread name for the main function is also what the kernel
@ -921,6 +943,7 @@ main(int argc, char *argv[])
catch_and_explain([&]() { catch_and_explain([&]() {
rv = bees_main(argc, argv); rv = bees_main(argc, argv);
}); });
BEESLOGNOTICE("Exiting with status " << rv << " " << (rv ? "(failure)" : "(success)"));
return rv; return rv;
} }

View File

@ -183,10 +183,13 @@ class BeesTracer {
BeesTracer *m_next_tracer = 0; BeesTracer *m_next_tracer = 0;
thread_local static BeesTracer *tl_next_tracer; thread_local static BeesTracer *tl_next_tracer;
thread_local static bool tl_silent;
public: public:
BeesTracer(function<void()> f); BeesTracer(function<void()> f, bool silent = false);
~BeesTracer(); ~BeesTracer();
static void trace_now(); static void trace_now();
static bool get_silent();
static void set_silent();
}; };
class BeesNote { class BeesNote {