aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-04-03 08:52:56 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-04-03 08:52:56 +0000
commitee3e2a7376c53c6007212fc035efc4572bebd924 (patch)
tree4e6fcbb9764d43754c5837ea907d0f6742a9811a /library/cpp
parentafb7a6aaa6828d57abdcf8dfdea8581fb98b89ec (diff)
parentd2527272d41073b1399b902b3a59218b894c8022 (diff)
downloadydb-ee3e2a7376c53c6007212fc035efc4572bebd924.tar.gz
Merge branch 'rightlib' into mergelibs-240403-0851
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/getopt/small/modchooser.cpp12
-rw-r--r--library/cpp/getopt/small/modchooser.h2
-rw-r--r--library/cpp/logger/ut/ya.make12
-rw-r--r--library/cpp/threading/future/ya.make4
-rw-r--r--library/cpp/tld/tlds-alpha-by-domain.txt3
-rw-r--r--library/cpp/yt/exception/attributes.h24
-rw-r--r--library/cpp/yt/exception/exception.cpp85
-rw-r--r--library/cpp/yt/exception/exception.h61
-rw-r--r--library/cpp/yt/exception/ya.make4
-rw-r--r--library/cpp/yt/misc/guid.cpp2
-rw-r--r--library/cpp/yt/misc/guid.h2
-rw-r--r--library/cpp/yt/string/string.cpp2
-rw-r--r--library/cpp/yt/string/string.h2
-rw-r--r--library/cpp/yt/yson_string/convert.h4
14 files changed, 166 insertions, 53 deletions
diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp
index bc319089b7c..3b3b0b7751e 100644
--- a/library/cpp/getopt/small/modchooser.cpp
+++ b/library/cpp/getopt/small/modchooser.cpp
@@ -250,19 +250,19 @@ size_t TModChooser::TMode::CalculateFullNameLen() const {
return len;
}
-TString TModChooser::TMode::FormatFullName(size_t pad) const {
+TString TModChooser::TMode::FormatFullName(size_t pad, const NColorizer::TColors& colors) const {
TStringBuilder name;
if (Aliases) {
name << "{";
}
- name << NColorizer::StdErr().GreenColor();
+ name << colors.GreenColor();
name << Name;
- name << NColorizer::StdErr().OldColor();
+ name << colors.OldColor();
if (Aliases) {
for (const auto& alias : Aliases) {
- name << "|" << NColorizer::StdErr().GreenColor() << alias << NColorizer::StdErr().OldColor();
+ name << "|" << colors.GreenColor() << alias << colors.OldColor();
}
name << "}";
}
@@ -294,7 +294,7 @@ void TModChooser::PrintHelp(const TString& progName, bool toStdErr) const {
for (const auto& unsortedMode : UnsortedModes)
if (!unsortedMode->Hidden) {
if (unsortedMode->Name.size()) {
- out << " " << unsortedMode->FormatFullName(maxModeLen + 4) << unsortedMode->Description << Endl;
+ out << " " << unsortedMode->FormatFullName(maxModeLen + 4, colors) << unsortedMode->Description << Endl;
} else {
out << SeparationString << Endl;
out << unsortedMode->Description << Endl;
@@ -306,7 +306,7 @@ void TModChooser::PrintHelp(const TString& progName, bool toStdErr) const {
continue; // this is an alias
if (!mode.second->Hidden) {
- out << " " << mode.second->FormatFullName(maxModeLen + 4) << mode.second->Description << Endl;
+ out << " " << mode.second->FormatFullName(maxModeLen + 4, colors) << mode.second->Description << Endl;
}
}
}
diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h
index 5ed64310c5a..d41ae780052 100644
--- a/library/cpp/getopt/small/modchooser.h
+++ b/library/cpp/getopt/small/modchooser.h
@@ -124,7 +124,7 @@ public:
// Full name includes primary name and aliases. Also, will add ANSI colors.
size_t CalculateFullNameLen() const;
- TString FormatFullName(size_t pad) const;
+ TString FormatFullName(size_t pad, const NColorizer::TColors& colors) const;
};
TVector<const TMode*> GetUnsortedModes() const {
diff --git a/library/cpp/logger/ut/ya.make b/library/cpp/logger/ut/ya.make
index c6fe244bd73..423219da58a 100644
--- a/library/cpp/logger/ut/ya.make
+++ b/library/cpp/logger/ut/ya.make
@@ -2,7 +2,6 @@ UNITTEST()
PEERDIR(
ADDINCL library/cpp/logger
- library/cpp/logger/init_context
library/cpp/yconf/patcher
)
@@ -12,8 +11,17 @@ SRCS(
log_ut.cpp
element_ut.cpp
rotating_file_ut.cpp
- composite_ut.cpp
reopen_ut.cpp
)
+IF (NOT OPENSOURCE OR OPENSOURCE_PROJECT != "catboost")
+ PEERDIR(
+ library/cpp/logger/init_context
+ )
+
+ SRCS(
+ composite_ut.cpp
+ )
+ENDIF()
+
END()
diff --git a/library/cpp/threading/future/ya.make b/library/cpp/threading/future/ya.make
index 32b54ff5180..bc52ca5c180 100644
--- a/library/cpp/threading/future/ya.make
+++ b/library/cpp/threading/future/ya.make
@@ -1,7 +1,3 @@
-SUBSCRIBER(
- swarmer
-)
-
LIBRARY()
SRCS(
diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt
index a9ad25f62a2..374cf501922 100644
--- a/library/cpp/tld/tlds-alpha-by-domain.txt
+++ b/library/cpp/tld/tlds-alpha-by-domain.txt
@@ -1,4 +1,4 @@
-# Version 2024032400, Last Updated Sun Mar 24 07:07:02 2024 UTC
+# Version 2024033102, Last Updated Mon Apr 1 07:07:01 2024 UTC
AAA
AARP
ABB
@@ -85,7 +85,6 @@ AUSPOST
AUTHOR
AUTO
AUTOS
-AVIANCA
AW
AWS
AX
diff --git a/library/cpp/yt/exception/attributes.h b/library/cpp/yt/exception/attributes.h
new file mode 100644
index 00000000000..f60d733880d
--- /dev/null
+++ b/library/cpp/yt/exception/attributes.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <library/cpp/yt/misc/guid.h>
+
+#include <util/generic/string.h>
+
+#include <variant>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+struct TExceptionAttribute
+{
+ using TKey = TString;
+ using TValue = std::variant<i64, double, bool, TString>;
+
+ TKey Key;
+ TValue Value;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/library/cpp/yt/exception/exception.cpp b/library/cpp/yt/exception/exception.cpp
index 2729511d5a6..71ece1ff2e0 100644
--- a/library/cpp/yt/exception/exception.cpp
+++ b/library/cpp/yt/exception/exception.cpp
@@ -1,48 +1,99 @@
#include "exception.h"
+#include <library/cpp/yt/assert/assert.h>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-TSimpleException::TSimpleException(TString message)
- : Message_(std::move(message))
-{ }
+namespace {
-const TString& TSimpleException::GetMessage() const
+template <class TRange>
+void AddAttributes(TSimpleException::TAttributes& attrs, TRange&& range)
{
- return Message_;
+ for (auto&& [key, value] : range) {
+ YT_VERIFY(attrs.emplace(std::move(key), std::move(value)).second);
+ }
}
-const char* TSimpleException::what() const noexcept
-{
- return Message_.c_str();
-}
+} // namespace
////////////////////////////////////////////////////////////////////////////////
-TCompositeException::TCompositeException(TString message)
- : TSimpleException(std::move(message))
+TSimpleException::TSimpleException(TString message)
+ : Message_(std::move(message))
, What_(Message_)
{ }
-TCompositeException::TCompositeException(
+TSimpleException::TSimpleException(
const std::exception& exception,
TString message)
- : TSimpleException(message)
- , InnerException_(std::current_exception())
- , What_(message + "\n" + exception.what())
+ : InnerException_(std::current_exception())
+ , Message_(std::move(message))
+ , What_(Message_ + "\n" + exception.what())
{ }
-const std::exception_ptr& TCompositeException::GetInnerException() const
+const std::exception_ptr& TSimpleException::GetInnerException() const
{
return InnerException_;
}
-const char* TCompositeException::what() const noexcept
+const char* TSimpleException::what() const noexcept
{
return What_.c_str();
}
+const TString& TSimpleException::GetMessage() const
+{
+ return Message_;
+}
+
+const TSimpleException::TAttributes& TSimpleException::GetAttributes() const &
+{
+ return Attributes_;
+}
+
+TSimpleException::TAttributes&& TSimpleException::GetAttributes() &&
+{
+ return std::move(Attributes_);
+}
+
+TSimpleException& TSimpleException::operator<<= (TExceptionAttribute&& attribute) &
+{
+ YT_VERIFY(Attributes_.emplace(std::move(attribute.Key), std::move(attribute.Value)).second);
+ return *this;
+}
+
+TSimpleException& TSimpleException::operator<<= (std::vector<TExceptionAttribute>&& attributes) &
+{
+ AddAttributes(Attributes_, std::move(attributes));
+ return *this;
+}
+
+TSimpleException& TSimpleException::operator<<= (TAttributes&& attributes) &
+{
+ AddAttributes(Attributes_, std::move(attributes));
+ return *this;
+}
+
+TSimpleException& TSimpleException::operator<<= (const TExceptionAttribute& attribute) &
+{
+ YT_VERIFY(Attributes_.emplace(attribute.Key, attribute.Value).second);
+ return *this;
+}
+
+TSimpleException& TSimpleException::operator<<= (const std::vector<TExceptionAttribute>& attributes) &
+{
+ AddAttributes(Attributes_, attributes);
+ return *this;
+}
+
+TSimpleException& TSimpleException::operator<<= (const TAttributes& attributes) &
+{
+ AddAttributes(Attributes_, attributes);
+ return *this;
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
diff --git a/library/cpp/yt/exception/exception.h b/library/cpp/yt/exception/exception.h
index 1ac3a76ea4b..2898b99f0de 100644
--- a/library/cpp/yt/exception/exception.h
+++ b/library/cpp/yt/exception/exception.h
@@ -1,43 +1,74 @@
#pragma once
-#include <util/generic/string.h>
+#include "attributes.h"
+
+#include <util/generic/hash.h>
#include <exception>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
-// These are poor man's versions of NYT::TErrorException to be used in
+// This is poor man's version of NYT::TErrorException to be used in
// a limited subset of core libraries that are needed to implement NYT::TError.
class TSimpleException
: public std::exception
{
public:
- explicit TSimpleException(TString message);
-
- const TString& GetMessage() const;
- const char* what() const noexcept override;
+ using TAttributes = THashMap<
+ TExceptionAttribute::TKey,
+ TExceptionAttribute::TValue>;
-protected:
- const TString Message_;
-};
+ template <class TValue>
+ static constexpr bool CNestable = requires (TSimpleException& ex, TValue&& operand) {
+ { ex <<= std::forward<TValue>(operand) } -> std::same_as<TSimpleException&>;
+ };
-class TCompositeException
- : public TSimpleException
-{
-public:
- explicit TCompositeException(TString message);
- TCompositeException(
+ explicit TSimpleException(TString message);
+ TSimpleException(
const std::exception& exception,
TString message);
const std::exception_ptr& GetInnerException() const;
const char* what() const noexcept override;
+ const TString& GetMessage() const;
+
+ const TAttributes& GetAttributes() const &;
+ TAttributes&& GetAttributes() &&;
+
+ TSimpleException& operator<<= (TExceptionAttribute&& attribute) &;
+ TSimpleException& operator<<= (std::vector<TExceptionAttribute>&& attributes) &;
+ TSimpleException& operator<<= (TAttributes&& attributes) &;
+
+ TSimpleException& operator<<= (const TExceptionAttribute& attribute) &;
+ TSimpleException& operator<<= (const std::vector<TExceptionAttribute>& attributes) &;
+ TSimpleException& operator<<= (const TAttributes& attributes) &;
+
+ // NB: clang is incapable of parsing such requirements (which refer back to the class) out-of-line.
+ // To keep this overload from winning in resolution
+ // when constraint actually fails, we define method right here.
+ template <class TValue>
+ requires CNestable<TValue>
+ TSimpleException&& operator<< (TValue&& value) &&
+ {
+ return std::move(*this <<= std::forward<TValue>(value));
+ }
+
+ template <class TValue>
+ requires CNestable<TValue>
+ TSimpleException operator<< (TValue&& value) const &
+ {
+ return TSimpleException(*this) << std::forward<TValue>(value);
+ }
+
private:
const std::exception_ptr InnerException_;
+ const TString Message_;
const TString What_;
+
+ TAttributes Attributes_;
};
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/exception/ya.make b/library/cpp/yt/exception/ya.make
index ff0014adcf9..954a9aca6e6 100644
--- a/library/cpp/yt/exception/ya.make
+++ b/library/cpp/yt/exception/ya.make
@@ -6,4 +6,8 @@ SRCS(
exception.cpp
)
+PEERDIR(
+ library/cpp/yt/assert
+)
+
END()
diff --git a/library/cpp/yt/misc/guid.cpp b/library/cpp/yt/misc/guid.cpp
index 02c396b0150..fc4f1465328 100644
--- a/library/cpp/yt/misc/guid.cpp
+++ b/library/cpp/yt/misc/guid.cpp
@@ -1,5 +1,7 @@
#include "guid.h"
+#include <library/cpp/yt/exception/exception.h>
+
#include <util/random/random.h>
#include <util/string/printf.h>
diff --git a/library/cpp/yt/misc/guid.h b/library/cpp/yt/misc/guid.h
index 05844ba49c6..48912b105fa 100644
--- a/library/cpp/yt/misc/guid.h
+++ b/library/cpp/yt/misc/guid.h
@@ -3,8 +3,6 @@
#include <util/generic/string.h>
#include <util/generic/typetraits.h>
-#include <library/cpp/yt/exception/exception.h>
-
#include <array>
namespace NYT {
diff --git a/library/cpp/yt/string/string.cpp b/library/cpp/yt/string/string.cpp
index a96f212cdfa..c4bd98b66c0 100644
--- a/library/cpp/yt/string/string.cpp
+++ b/library/cpp/yt/string/string.cpp
@@ -3,6 +3,8 @@
#include <library/cpp/yt/assert/assert.h>
+#include <library/cpp/yt/exception/exception.h>
+
#include <util/generic/hash.h>
#include <util/string/ascii.h>
diff --git a/library/cpp/yt/string/string.h b/library/cpp/yt/string/string.h
index 04eb115cb27..a131b40a2a1 100644
--- a/library/cpp/yt/string/string.h
+++ b/library/cpp/yt/string/string.h
@@ -2,8 +2,6 @@
#include "string_builder.h"
-#include <library/cpp/yt/exception/exception.h>
-
#include <util/datetime/base.h>
#include <util/generic/string.h>
diff --git a/library/cpp/yt/yson_string/convert.h b/library/cpp/yt/yson_string/convert.h
index 3c2cc7d2840..06de28d2f9d 100644
--- a/library/cpp/yt/yson_string/convert.h
+++ b/library/cpp/yt/yson_string/convert.h
@@ -69,10 +69,10 @@ TYsonString ConvertToYsonString<TGuid>(const TGuid& value);
// Note: these currently support a subset of NYT::NYTree::Convert features.
class TYsonLiteralParseException
- : public TCompositeException
+ : public TSimpleException
{
public:
- using TCompositeException::TCompositeException;
+ using TSimpleException::TSimpleException;
};
template <>