diff --git a/src/bees-resolve.cc b/src/bees-resolve.cc index 0634005..5a877cc 100644 --- a/src/bees-resolve.cc +++ b/src/bees-resolve.cc @@ -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"); } diff --git a/src/bees.cc b/src/bees.cc index 7267c06..183d6ba 100644 --- a/src/bees.cc +++ b/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 f) : +BeesTracer::BeesTracer(function 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"); - BEESCOUNT(exception_caught); + 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; } diff --git a/src/bees.h b/src/bees.h index 3ef655d..f2b6a04 100644 --- a/src/bees.h +++ b/src/bees.h @@ -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 f); + BeesTracer(function f, bool silent = false); ~BeesTracer(); static void trace_now(); + static bool get_silent(); + static void set_silent(); }; class BeesNote {