diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-04-03 08:52:56 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-04-03 08:52:56 +0000 |
commit | ee3e2a7376c53c6007212fc035efc4572bebd924 (patch) | |
tree | 4e6fcbb9764d43754c5837ea907d0f6742a9811a /library/cpp/yt/exception/exception.cpp | |
parent | afb7a6aaa6828d57abdcf8dfdea8581fb98b89ec (diff) | |
parent | d2527272d41073b1399b902b3a59218b894c8022 (diff) | |
download | ydb-ee3e2a7376c53c6007212fc035efc4572bebd924.tar.gz |
Merge branch 'rightlib' into mergelibs-240403-0851
Diffstat (limited to 'library/cpp/yt/exception/exception.cpp')
-rw-r--r-- | library/cpp/yt/exception/exception.cpp | 85 |
1 files changed, 68 insertions, 17 deletions
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 |