diff options
| -rw-r--r-- | library/cpp/yt/error/error.cpp | 1 | ||||
| -rw-r--r-- | library/cpp/yt/error/unittests/error_ut.cpp | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/library/cpp/yt/error/error.cpp b/library/cpp/yt/error/error.cpp index f097697cd6a..ea71a07feed 100644 --- a/library/cpp/yt/error/error.cpp +++ b/library/cpp/yt/error/error.cpp @@ -275,6 +275,7 @@ TError::TErrorOr(const std::exception& ex) *this = errorEx->Error(); } else { *this = TError(NYT::EErrorCode::Generic, TRuntimeFormat{ex.what()}); + *this <<= TErrorAttribute("exception_type", TypeName(ex)); } YT_VERIFY(!IsOK()); Enrich(); diff --git a/library/cpp/yt/error/unittests/error_ut.cpp b/library/cpp/yt/error/unittests/error_ut.cpp index 198aa1ecd8b..a5576fad58a 100644 --- a/library/cpp/yt/error/unittests/error_ut.cpp +++ b/library/cpp/yt/error/unittests/error_ut.cpp @@ -397,6 +397,22 @@ TEST(TErrorTest, FormatCtor) EXPECT_EQ("Some error hello", TError("Some error %v", "hello").GetMessage()); } +TEST(TErrorTest, ExceptionCtor) +{ + { + auto error = TError(std::runtime_error("Some error")); + EXPECT_EQ(error.GetMessage(), "Some error"); + EXPECT_EQ(error.Attributes().Get<std::string>("exception_type"), "std::runtime_error"); + } + EXPECT_EQ(TError(std::runtime_error("Some bad char sequences: %v %Qv {}")).GetMessage(), + "Some bad char sequences: %v %Qv {}"); + + EXPECT_EQ(TError(TSimpleException("Some error")).GetMessage(), + "Some error"); + EXPECT_EQ(TError(TSimpleException("Some bad char sequences: %v %d {}")).GetMessage(), + "Some bad char sequences: %v %d {}"); +} + TEST(TErrorTest, FindRecursive) { auto inner = TError("Inner") |
