From 811197558cc2695e1ff352dafbd06f4bab78b087 Mon Sep 17 00:00:00 2001 From: Nicolae Vartolomei Date: Wed, 19 Feb 2020 13:33:31 +0000 Subject: [PATCH] Improve stack trace formatting for Poco and std exceptions Before: ``` Application: Caught exception while loading metadata: Poco::Exception. Code: 1000, e.code() = 0, e.displayText() = Access to file denied: boo0. /home/nv/clickhouse-master-clion/contrib/poco/Foundation/src/Exception.cpp:27: Poco::FileAccessDeniedException::FileAccessDeniedException(std::__1::basic_string, std::__1::allocator > const&, int) @ 0xbb598cc in /state/home/nv/clickhouse-builds/clickhouse-master-clion-gcc/dbms/programs/clickhous ``` After: ``` Application: Caught exception while loading metadata: Poco::Exception. Code: 1000, e.code() = 0, e.displayText() = Access to file denied: boo, Stack trace (when copying this message, always include the lines below): 0. /home/nv/clickhouse-master-clion/contrib/poco/Foundation/src/Exception.cpp:27: Poco::FileAccessDeniedException::FileAccessDeniedException(std::__1::basic_string, std::__1::allocator > const&, int) @ 0xbb5987c in /state/home/nv/clickhouse-builds/clickhouse-master-clion-gcc/dbms/programs/clickhous ``` --- dbms/src/Common/Exception.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbms/src/Common/Exception.cpp b/dbms/src/Common/Exception.cpp index 318da1a27f2..00ef520f37c 100644 --- a/dbms/src/Common/Exception.cpp +++ b/dbms/src/Common/Exception.cpp @@ -193,7 +193,7 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded { stream << "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION << ", e.code() = " << e.code() << ", e.displayText() = " << e.displayText() - << (with_stacktrace ? getExceptionStackTraceString(e) : "") + << (with_stacktrace ? ", Stack trace (when copying this message, always include the lines below):\n\n" + getExceptionStackTraceString(e) : "") << (with_extra_info ? getExtraExceptionInfo(e) : "") << " (version " << VERSION_STRING << VERSION_OFFICIAL << ")"; } @@ -210,9 +210,9 @@ std::string getCurrentExceptionMessage(bool with_stacktrace, bool check_embedded name += " (demangling status: " + toString(status) + ")"; stream << "std::exception. Code: " << ErrorCodes::STD_EXCEPTION << ", type: " << name << ", e.what() = " << e.what() - << (with_stacktrace ? getExceptionStackTraceString(e) : "") + << (with_stacktrace ? ", Stack trace (when copying this message, always include the lines below):\n\n" + getExceptionStackTraceString(e) : "") << (with_extra_info ? getExtraExceptionInfo(e) : "") - << ", version = " << VERSION_STRING << VERSION_OFFICIAL; + << " (version " << VERSION_STRING << VERSION_OFFICIAL << ")"; } catch (...) {} }