diff options
| author | pechatnov <[email protected]> | 2026-07-21 09:21:36 +0300 |
|---|---|---|
| committer | pechatnov <[email protected]> | 2026-07-21 09:52:42 +0300 |
| commit | b6bda2264da6775be09d9224c82c5b9587e60052 (patch) | |
| tree | dd3a7f85efeb771683a414c782e2ef7f244fa318 /library/cpp | |
| parent | e41bc8350350c24080f8f88bff0d2429bd76a213 (diff) | |
Make THROW_ERROR_EXCEPTION_UNLESS/IF chainable with error attributes
commit_hash:4e76ece0b75ab787ed04b6be5f183cecbf9b8167
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/yt/error/error.h | 6 | ||||
| -rw-r--r-- | library/cpp/yt/error/unittests/error_ut.cpp | 13 |
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(); |
