aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-07-15 00:53:43 +0300
committerbabenko <babenko@yandex-team.com>2024-07-15 01:03:55 +0300
commit2059b14708ae359a6f6a5fccff4fd833cd2e7ecf (patch)
tree3c717b0bb577e1c62b94adf9fa47c74972da9339
parent610c67e56ddfdf36ce8e690fddf6fb56873e79a3 (diff)
downloadydb-2059b14708ae359a6f6a5fccff4fd833cd2e7ecf.tar.gz
TError::operator << for optionals
387a12a42b102c65972f1b188df1edd867cc74a5
-rw-r--r--yt/yt/core/misc/error-inl.h22
-rw-r--r--yt/yt/core/misc/error.h7
-rw-r--r--yt/yt/core/rpc/service_detail.cpp13
3 files changed, 29 insertions, 13 deletions
diff --git a/yt/yt/core/misc/error-inl.h b/yt/yt/core/misc/error-inl.h
index df5afad615..b51b9e5154 100644
--- a/yt/yt/core/misc/error-inl.h
+++ b/yt/yt/core/misc/error-inl.h
@@ -128,6 +128,26 @@ TError TError::operator << (TValue&& rhs) const &
return TError(*this) << std::forward<TValue>(rhs);
}
+template <CErrorNestable TValue>
+TError&& TError::operator << (const std::optional<TValue>& rhs) &&
+{
+ if (rhs) {
+ return std::move(*this <<= *rhs);
+ } else {
+ return std::move(*this);
+ }
+}
+
+template <CErrorNestable TValue>
+TError TError::operator << (const std::optional<TValue>& rhs) const &
+{
+ if (rhs) {
+ return TError(*this) << *rhs;
+ } else {
+ return *this;
+ }
+}
+
template <class... TArgs>
void TError::ThrowOnError(TArgs&&... args) const
{
@@ -369,4 +389,6 @@ void ThrowErrorExceptionIfFailed(TErrorLike&& error, TArgs&&... args)
} // namespace NDetail
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
diff --git a/yt/yt/core/misc/error.h b/yt/yt/core/misc/error.h
index 4eb7d15475..742935583f 100644
--- a/yt/yt/core/misc/error.h
+++ b/yt/yt/core/misc/error.h
@@ -57,6 +57,7 @@ public:
constexpr bool operator == (E rhs) const;
constexpr bool operator == (TErrorCode rhs) const;
+
private:
int Value_;
};
@@ -232,10 +233,14 @@ public:
template <CErrorNestable TValue>
TError&& operator << (TValue&& operand) &&;
-
template <CErrorNestable TValue>
TError operator << (TValue&& operand) const &;
+ template <CErrorNestable TValue>
+ TError&& operator << (const std::optional<TValue>& operand) &&;
+ template <CErrorNestable TValue>
+ TError operator << (const std::optional<TValue>& operand) const &;
+
private:
class TImpl;
std::unique_ptr<TImpl> Impl_;
diff --git a/yt/yt/core/rpc/service_detail.cpp b/yt/yt/core/rpc/service_detail.cpp
index 5581919639..f3734d03ef 100644
--- a/yt/yt/core/rpc/service_detail.cpp
+++ b/yt/yt/core/rpc/service_detail.cpp
@@ -32,17 +32,6 @@
#include <library/cpp/yt/misc/tls.h>
-namespace NYT
-{
- static TError operator<<(TError error, const std::optional<TError>& maybeError)
- {
- if (maybeError) {
- return error << *maybeError;
- }
- return error;
- }
-}
-
namespace NYT::NRpc {
using namespace NBus;
@@ -60,7 +49,7 @@ using NYT::ToProto;
static const auto InfiniteRequestThrottlerConfig = New<TThroughputThrottlerConfig>();
static const auto DefaultLoggingSuppressionFailedRequestThrottlerConfig = TThroughputThrottlerConfig::Create(1'000);
-constexpr TDuration ServiceLivenessCheckPeriod = TDuration::MilliSeconds(100);
+constexpr auto ServiceLivenessCheckPeriod = TDuration::MilliSeconds(100);
////////////////////////////////////////////////////////////////////////////////