From 6dfd9c227e4fc1d946021b3f7a922256294b426c Mon Sep 17 00:00:00 2001 From: yoko Date: Wed, 20 Mar 2024 22:24:36 -0700 Subject: [PATCH] Ugly hotfix for "terminate on uncaught exception" in WriteBufferFromOStream porting ClickHouse/ClickHouse#51265 --- src/IO/WriteBufferFromOStream.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/IO/WriteBufferFromOStream.cpp b/src/IO/WriteBufferFromOStream.cpp index 1d950fded28..9095b2aea52 100644 --- a/src/IO/WriteBufferFromOStream.cpp +++ b/src/IO/WriteBufferFromOStream.cpp @@ -1,5 +1,5 @@ #include - +#include namespace DB { @@ -18,8 +18,14 @@ void WriteBufferFromOStream::nextImpl() ostr->flush(); if (!ostr->good()) - throw Exception("Cannot write to ostream at offset " + std::to_string(count()), - ErrorCodes::CANNOT_WRITE_TO_OSTREAM); + { + /// FIXME do not call finalize in dtors (and remove iostreams) + bool avoid_throwing_exceptions = std::uncaught_exceptions(); + if (avoid_throwing_exceptions) + LOG_ERROR(&Poco::Logger::get("WriteBufferFromOStream"), "Cannot write to ostream at offset {}. Stack trace: {}", count(), StackTrace().toString()); + else + throw Exception(ErrorCodes::CANNOT_WRITE_TO_OSTREAM, "Cannot write to ostream at offset {}", count()); + } } WriteBufferFromOStream::WriteBufferFromOStream(