aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-10-16 10:57:50 +0300
committerarkady-e1ppa <arkady-e1ppa@yandex-team.com>2024-10-16 11:12:35 +0300
commit06315bfc9a9c00a74cf70cd35d65c959bd036f7c (patch)
tree3b263b24962c0fb4823a4a6f08588671ecbc3c89
parente62cc482cdc5b8df45bea71fa108c44fc391cdc8 (diff)
downloadydb-06315bfc9a9c00a74cf70cd35d65c959bd036f7c.tar.gz
Fancier error messages upon static analysis check failure
commit_hash:f939fba86939275047d2eca49b11bec3d0ea3ce7
-rw-r--r--library/cpp/yt/logging/unittests/static_analysis_ut.cpp18
-rw-r--r--library/cpp/yt/string/format_analyser.h40
2 files changed, 15 insertions, 43 deletions
diff --git a/library/cpp/yt/logging/unittests/static_analysis_ut.cpp b/library/cpp/yt/logging/unittests/static_analysis_ut.cpp
index 7fb4c0150c..b9a01b334f 100644
--- a/library/cpp/yt/logging/unittests/static_analysis_ut.cpp
+++ b/library/cpp/yt/logging/unittests/static_analysis_ut.cpp
@@ -23,15 +23,15 @@ TEST(TStaticAnalysisTest, ValidFormats)
}
// Uncomment this test to see that we don't have false negatives!
-// TEST(TStaticAnalysisTest, InvalidFormats)
-// {
-// YT_LOG_INFO("Hello", 1);
-// YT_LOG_INFO("Hello %");
-// YT_LOG_INFO("Hello %false");
-// YT_LOG_INFO("Hello ", "World");
-// YT_LOG_INFO("Hello ", "(World: %v)", 42);
-// YT_LOG_INFO("Hello %lbov", 42); // There is no 'b' flag.
-// }
+TEST(TStaticAnalysisTest, InvalidFormats)
+{
+ // YT_LOG_INFO("Hello", 1);
+ // YT_LOG_INFO("Hello %");
+ // YT_LOG_INFO("Hello %false");
+ // YT_LOG_INFO("Hello ", "World");
+ // YT_LOG_INFO("Hello ", "(World: %v)", 42);
+ // YT_LOG_INFO("Hello %lbov", 42); // There is no 'b' flag.
+}
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/string/format_analyser.h b/library/cpp/yt/string/format_analyser.h
index e8287ea8f3..20eee60580 100644
--- a/library/cpp/yt/string/format_analyser.h
+++ b/library/cpp/yt/string/format_analyser.h
@@ -24,27 +24,6 @@ public:
}
private:
- // Non-constexpr function call will terminate compilation.
- // Purposefully undefined and non-constexpr/consteval
- template <class T>
- static void CrashCompilerNotFormattable(std::string_view /*msg*/)
- { /*Suppress "internal linkage but undefined" warning*/ }
- static void CrashCompilerNotEnoughArguments(std::string_view /*msg*/)
- { }
-
- static void CrashCompilerTooManyArguments(std::string_view /*msg*/)
- { }
-
- static void CrashCompilerWrongTermination(std::string_view /*msg*/)
- { }
-
- static void CrashCompilerMissingTermination(std::string_view /*msg*/)
- { }
-
- static void CrashCompilerWrongFlagSpecifier(std::string_view /*msg*/)
- { }
-
-
static consteval bool Contains(std::string_view sv, char symbol)
{
return sv.find(symbol) != std::string_view::npos;
@@ -59,10 +38,6 @@ private:
template <class TArg>
static consteval auto GetSpecifiers()
{
- if constexpr (!CFormattable<TArg>) {
- CrashCompilerNotFormattable<TArg>("Your specialization of TFormatArg is broken");
- }
-
return TSpecifiers{
.Conversion = std::string_view{
std::data(TFormatArg<TArg>::ConversionSpecifiers),
@@ -103,8 +78,7 @@ private:
if (symbol == IntroductorySymbol) {
if (currentMarkerStart + 1 != index) {
// '%a% detected'
- CrashCompilerWrongTermination("You may not terminate flag sequence other than %% with \'%\' symbol");
- return;
+ throw "You may not terminate flag sequence other than %% with \'%\' symbol";
}
// '%%' detected --- skip
currentMarkerStart = -1;
@@ -113,9 +87,8 @@ private:
// We are inside of marker.
if (markerCount == std::ssize(markers)) {
- // To many markers
- CrashCompilerNotEnoughArguments("Number of arguments supplied to format is smaller than the number of flag sequences");
- return;
+ // Too many markers
+ throw "Number of arguments supplied to format is smaller than the number of flag sequences";
}
if (Contains(specifiers[markerCount].Conversion, symbol)) {
@@ -130,20 +103,19 @@ private:
}
if (!Contains(specifiers[markerCount].Flags, symbol)) {
- CrashCompilerWrongFlagSpecifier("Symbol is not a valid flag specifier; See FlagSpecifiers");
+ throw "Symbol is not a valid flag specifier; See FlagSpecifiers";
}
}
if (currentMarkerStart != -1) {
// Runaway marker.
- CrashCompilerMissingTermination("Unterminated flag sequence detected; Use \'%%\' to type plain %");
+ throw "Unterminated flag sequence detected; Use \'%%\' to type plain %";
return;
}
if (markerCount < std::ssize(markers)) {
// Missing markers.
- CrashCompilerTooManyArguments("Number of arguments supplied to format is greater than the number of flag sequences");
- return;
+ throw "Number of arguments supplied to format is greater than the number of flag sequences";
}
// TODO(arkady-e1ppa): Consider per-type verification