From cef923f9d94dfa53f612c1939b9162c1b5f5f664 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sun, 20 Oct 2024 22:20:47 +0200 Subject: [PATCH] chore(logger): catch errors during fmt::print (gh #241) --- src/logger.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/logger.cpp b/src/logger.cpp index f4ba63db1..fa87085e3 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -149,7 +150,12 @@ std::string_view stream_logger::get_newline() const { return "\n"; } void stream_logger::write_nolock(std::string_view output) { if (&os_ == &std::cerr) { - fmt::print(stderr, "{}", output); + try { + fmt::print(stderr, "{}", output); + } catch (...) { + fmt::print(stderr, "Unexpected error writing string:\n{}", + folly::hexDump(output.data(), output.size())); + } } else { os_ << output; }