diff options
| author | pechatnov <[email protected]> | 2025-04-01 14:51:45 +0300 |
|---|---|---|
| committer | pechatnov <[email protected]> | 2025-04-01 15:13:05 +0300 |
| commit | 15459267fcda53b29241b23b6fe98b1134986b53 (patch) | |
| tree | f570673b9267ebeb207bc336ed0057370542d3b3 /library | |
| parent | 3abc20a83ce4395d801ed44adf6fcada986ed818 (diff) | |
YT: Add type name of std::exception to error text in TError constructor
Без этого, исключение о выходе за пределы массива в векторе выглядит так:
```
vector
origin (pid 178121, thread library-cpp-yt-)
datetime 2025-03-31T14:59:49.069209Z
```
С фиксом:
```
vector
origin (pid 178121, thread library-cpp-yt-)
datetime 2025-03-31T14:59:49.069209Z
exception_type std::out_of_range
```
commit_hash:7382eba16208f6847d581b901a7df4dfa39452b0
Diffstat (limited to 'library')
| -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") |
