From fa10d601265343a64d9d5b7b32eb133010b24127 Mon Sep 17 00:00:00 2001 From: pechatnov Date: Tue, 6 May 2025 11:09:14 +0300 Subject: YT: Fix enricher, add from backtrace enricher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From backtrace enricher можно использовать для захвата бектрейсов при создании ошибок из исключений, а так же для перекладывания атрибутов из сложных исключений других библиотек. commit_hash:76711bd3bb7dbc1e41e43f80d43340d2ce8e4df7 --- library/cpp/yt/error/error.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'library/cpp/yt/error/error.h') diff --git a/library/cpp/yt/error/error.h b/library/cpp/yt/error/error.h index 92f19bc398a..4b329105bcb 100644 --- a/library/cpp/yt/error/error.h +++ b/library/cpp/yt/error/error.h @@ -219,13 +219,20 @@ public: template TError operator << (const std::optional& rhs) const &; - // The |enricher| is called during TError construction and before TErrorOr<> construction. Meant - // to enrich the error, e.g. by setting generic attributes. The |RegisterEnricher| method is not + // The |enricher| is called during TError initial construction and before TErrorOr<> construction. Meant + // to enrich the error, e.g. by setting generic attributes. Copying TError from another TError or TErrorException + // doesn't call enrichers. The |RegisterEnricher| method is not // threadsafe and is meant to be called from single-threaded bootstrapping code. Multiple // enrichers are supported and will be called in order of registration. - using TEnricher = std::function; + using TEnricher = std::function; static void RegisterEnricher(TEnricher enricher); + // The |enricher| is called during TError every construction from std::exception (including TErrorException). + // The |RegisterFromExceptionEnricher| method is not threadsafe and is meant to be called from single-threaded + // bootstrapping code. Multiple enrichers are supported and will be called in order of registration. + using TFromExceptionEnricher = std::function; + static void RegisterFromExceptionEnricher(TFromExceptionEnricher enricher); + private: class TImpl; std::unique_ptr Impl_; @@ -234,10 +241,12 @@ private: void MakeMutable(); void Enrich(); + void EnrichFromException(const std::exception& exception); friend class TErrorAttributes; static TEnricher Enricher_; + static TFromExceptionEnricher FromExceptionEnricher_; }; //////////////////////////////////////////////////////////////////////////////// -- cgit v1.3