summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/error
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp/yt/error')
-rw-r--r--library/cpp/yt/error/error.h6
-rw-r--r--library/cpp/yt/error/unittests/error_ut.cpp13
2 files changed, 15 insertions, 4 deletions
diff --git a/library/cpp/yt/error/error.h b/library/cpp/yt/error/error.h
index 1e5c2147d82..73904315065 100644
--- a/library/cpp/yt/error/error.h
+++ b/library/cpp/yt/error/error.h
@@ -370,10 +370,8 @@ void ThrowErrorExceptionIfFailed(TErrorLike&& error);
::NYT::NDetail::ThrowErrorExceptionIfFailed((error) __VA_OPT__(,) __VA_ARGS__) \
#define THROW_ERROR_EXCEPTION_UNLESS(condition, head, ...) \
- if ((condition)) {\
- } else { \
- THROW_ERROR ::NYT::TError(head __VA_OPT__(,) __VA_ARGS__); \
- }
+ if ((condition)) {} else \
+ THROW_ERROR ::NYT::TError(head __VA_OPT__(,) __VA_ARGS__)
#define THROW_ERROR_EXCEPTION_IF(condition, head, ...) \
THROW_ERROR_EXCEPTION_UNLESS(!(condition), head, __VA_ARGS__)
diff --git a/library/cpp/yt/error/unittests/error_ut.cpp b/library/cpp/yt/error/unittests/error_ut.cpp
index e7cbbcd21d8..4cba6ca563f 100644
--- a/library/cpp/yt/error/unittests/error_ut.cpp
+++ b/library/cpp/yt/error/unittests/error_ut.cpp
@@ -395,6 +395,19 @@ TEST(TErrorTest, ThrowErrorExceptionIfFailedMacroExpression)
}
}
+TEST(TErrorTest, ThrowErrorExceptionIfMacroAttributes)
+{
+ try {
+ THROW_ERROR_EXCEPTION_IF(true, "Condition holds")
+ << TErrorAttribute("attr", "attr_value");
+ ADD_FAILURE() << "Expected the macro to throw.";
+ } catch (const std::exception& ex) {
+ TError error(ex);
+ EXPECT_EQ(error.GetMessage(), "Condition holds");
+ EXPECT_EQ(error.Attributes().Get<std::string>("attr"), "attr_value");
+ }
+}
+
TEST(TErrorTest, ThrowErrorExceptionIfFailedMacroDontStealValue)
{
TErrorOr<TWidget> widget = TWidget();