forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ClickHouse#45342 from ClickHouse/exception_message…
…_patterns Save message format strings for DB::Exception
- Loading branch information
Showing
67 changed files
with
380 additions
and
304 deletions.
There are no files selected for viewing
Submodule poco
updated
2 files
+3 −0 | Foundation/include/Poco/Exception.h | |
+4 −0 | Foundation/src/Exception.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
#include <base/defines.h> | ||
#include <fmt/format.h> | ||
|
||
/// Saves a format string for already formatted message | ||
struct PreformattedMessage | ||
{ | ||
String message; | ||
std::string_view format_string; | ||
|
||
operator const String & () const { return message; } | ||
operator String () && { return std::move(message); } | ||
operator fmt::format_string<> () const { UNREACHABLE(); } | ||
}; | ||
|
||
template<typename T> struct is_fmt_runtime : std::false_type {}; | ||
template<typename T> struct is_fmt_runtime<fmt::basic_runtime<T>> : std::true_type {}; | ||
|
||
template <typename T> constexpr std::string_view tryGetStaticFormatString(T && x) | ||
{ | ||
/// Failure of this asserting indicates that something went wrong during type deduction. | ||
/// For example, a string literal was implicitly converted to std::string. It should not happen. | ||
static_assert(!std::is_same_v<std::string, std::decay_t<T>>); | ||
|
||
if constexpr (is_fmt_runtime<std::decay_t<T>>::value) | ||
{ | ||
/// It definitely was fmt::runtime(something). | ||
/// We are not sure about a lifetime of the string, so return empty view. | ||
/// Also it can be arbitrary string, not a formatting pattern. | ||
/// So returning empty pattern will not pollute the set of patterns. | ||
return std::string_view(); | ||
} | ||
else | ||
{ | ||
if constexpr (std::is_same_v<PreformattedMessage, std::decay_t<T>>) | ||
{ | ||
return x.format_string; | ||
} | ||
else | ||
{ | ||
/// Most likely it was a string literal. | ||
/// Unfortunately, there's no good way to check if something is a string literal. | ||
/// But fmtlib requires a format string to be compile-time constant unless fmt::runtime is used. | ||
static_assert(std::is_nothrow_convertible<T, const char * const>::value); | ||
static_assert(!std::is_pointer<T>::value); | ||
return std::string_view(x); | ||
} | ||
} | ||
} | ||
|
||
template <typename... Ts> constexpr size_t numArgs(Ts &&...) { return sizeof...(Ts); } | ||
template <typename T, typename... Ts> constexpr auto firstArg(T && x, Ts &&...) { return std::forward<T>(x); } | ||
/// For implicit conversion of fmt::basic_runtime<> to char* for std::string ctor | ||
template <typename T, typename... Ts> constexpr auto firstArg(fmt::basic_runtime<T> && data, Ts &&...) { return data.str.data(); } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.