Skip to content

Commit 021c7d0

Browse files
committed
Base: Prevent an exception from leaking out of Console() calls
These are sometimes used in destructors, where a raised exception calls terminate()
1 parent 9c097eb commit 021c7d0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Base/Console.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,17 @@ template<Base::LogStyle category,
11691169
inline void
11701170
Base::ConsoleSingleton::Send(const std::string& notifiername, const char* pMsg, Args&&... args)
11711171
{
1172-
std::string format = fmt::sprintf(pMsg, args...);
1172+
std::string format;
1173+
try {
1174+
format = fmt::sprintf(pMsg, args...);
1175+
}
1176+
catch (fmt::format_error& e) {
1177+
// We can't allow an exception to propagate out of this method, which gets used in some
1178+
// destructors. Instead, make the string's contents the error message that fmt::sprintf gave
1179+
// us.
1180+
format = std::string("ERROR: Invalid format string or arguments provided.\n");
1181+
format += e.what();
1182+
}
11731183

11741184
if (connectionMode == Direct) {
11751185
Notify<category, recipient, contenttype>(notifiername, format);

0 commit comments

Comments
 (0)