Skip to content

Commit

Permalink
chore(logger): catch errors during fmt::print (gh #241)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Oct 20, 2024
1 parent e5a972f commit f664352
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdexcept>

#include <folly/Conv.h>
#include <folly/String.h>
#include <folly/lang/Assume.h>
#include <folly/small_vector.h>

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f664352

Please sign in to comment.