| 645 | } |
| 646 | |
| 647 | PreformattedMessage getExceptionMessageAndPattern(const Exception & e, bool with_stacktrace, bool check_embedded_stacktrace) |
| 648 | { |
| 649 | WriteBufferFromOwnString stream; |
| 650 | |
| 651 | try |
| 652 | { |
| 653 | std::string text = e.displayText(); |
| 654 | |
| 655 | bool has_embedded_stack_trace = false; |
| 656 | if (check_embedded_stacktrace) |
| 657 | { |
| 658 | auto embedded_stack_trace_pos = text.find("Stack trace"); |
| 659 | has_embedded_stack_trace = embedded_stack_trace_pos != std::string::npos; |
| 660 | if (!with_stacktrace && has_embedded_stack_trace) |
| 661 | { |
| 662 | text.resize(embedded_stack_trace_pos); |
| 663 | Poco::trimRightInPlace(text); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | stream << "Code: " << e.code() << ". " << text; |
| 668 | |
| 669 | if (!text.empty() && text.back() != '.') |
| 670 | stream << '.'; |
| 671 | |
| 672 | stream << " (" << ErrorCodes::getName(e.code()) << ")"; |
| 673 | |
| 674 | if (with_stacktrace && !has_embedded_stack_trace) |
| 675 | stream << formatStackTraceSection(e.getStackTraceString()); |
| 676 | } |
| 677 | catch (...) {} // NOLINT(bugprone-empty-catch) Ok: best-effort exception formatting, must not throw |
| 678 | |
| 679 | return PreformattedMessage{stream.str(), e.tryGetMessageFormatString(), e.getMessageFormatStringArgs()}; |
| 680 | } |
| 681 | |
| 682 | std::string getExceptionMessage(std::exception_ptr e, bool with_stacktrace, bool check_embedded_stacktrace) |
| 683 | { |
no test coverage detected