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:
parent
4a1971bce5
commit
be2c55119e
@ -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()) {
|
||||
BEESCOUNT(replacedst_same);
|
||||
// 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");
|
||||
}
|
||||
|
||||
|
39
src/bees.cc
39
src/bees.cc
@ -78,41 +78,58 @@ do_cmd_help(char *argv[])
|
||||
// tracing ----------------------------------------
|
||||
|
||||
thread_local BeesTracer *BeesTracer::tl_next_tracer = nullptr;
|
||||
thread_local bool BeesTracer::tl_silent = false;
|
||||
|
||||
BeesTracer::~BeesTracer()
|
||||
{
|
||||
if (uncaught_exception()) {
|
||||
if (!tl_silent && uncaught_exception()) {
|
||||
try {
|
||||
m_func();
|
||||
} catch (exception &e) {
|
||||
BEESLOGERR("Nested exception: " << e.what());
|
||||
BEESLOGNOTICE("Nested exception: " << e.what());
|
||||
} catch (...) {
|
||||
BEESLOGERR("Nested exception ...");
|
||||
BEESLOGNOTICE("Nested exception ...");
|
||||
}
|
||||
if (!m_next_tracer) {
|
||||
BEESLOGERR("--- END TRACE --- exception ---");
|
||||
BEESLOGNOTICE("--- END TRACE --- exception ---");
|
||||
}
|
||||
}
|
||||
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_next_tracer = tl_next_tracer;
|
||||
tl_next_tracer = this;
|
||||
tl_silent = silent;
|
||||
}
|
||||
|
||||
void
|
||||
BeesTracer::trace_now()
|
||||
{
|
||||
BeesTracer *tp = tl_next_tracer;
|
||||
BEESLOGERR("--- BEGIN TRACE ---");
|
||||
BEESLOGNOTICE("--- BEGIN TRACE ---");
|
||||
while (tp) {
|
||||
tp->m_func();
|
||||
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;
|
||||
@ -721,8 +738,13 @@ int
|
||||
bees_main(int argc, char *argv[])
|
||||
{
|
||||
set_catch_explainer([&](string s) {
|
||||
BEESLOGERR("\n\n*** EXCEPTION ***\n\t" << s << "\n***\n");
|
||||
if (BeesTracer::get_silent()) {
|
||||
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
|
||||
@ -921,6 +943,7 @@ main(int argc, char *argv[])
|
||||
catch_and_explain([&]() {
|
||||
rv = bees_main(argc, argv);
|
||||
});
|
||||
BEESLOGNOTICE("Exiting with status " << rv << " " << (rv ? "(failure)" : "(success)"));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -183,10 +183,13 @@ class BeesTracer {
|
||||
BeesTracer *m_next_tracer = 0;
|
||||
|
||||
thread_local static BeesTracer *tl_next_tracer;
|
||||
thread_local static bool tl_silent;
|
||||
public:
|
||||
BeesTracer(function<void()> f);
|
||||
BeesTracer(function<void()> f, bool silent = false);
|
||||
~BeesTracer();
|
||||
static void trace_now();
|
||||
static bool get_silent();
|
||||
static void set_silent();
|
||||
};
|
||||
|
||||
class BeesNote {
|
||||
|
Loading…
x
Reference in New Issue
Block a user