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 Nov 20, 2024
1 parent ab26623 commit 711358a
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 @@ -25,6 +25,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 711358a

Please sign in to comment.