diff options
author | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-11-20 10:24:46 +0300 |
---|---|---|
committer | ivanmorozov <ivanmorozov@yandex-team.com> | 2023-11-20 10:40:50 +0300 |
commit | d939e18f7bdc05d2db3b99404d73840cf24b796a (patch) | |
tree | 3f17a6e3413dbb295a28ecb47b6ffa57c2224cf8 | |
parent | c3c9ba92e055a8db262ef921ec9cdd20a5321e5c (diff) | |
download | ydb-d939e18f7bdc05d2db3b99404d73840cf24b796a.tar.gz |
AFL_ENSURE macros for AFL context usage in exception
-rw-r--r-- | library/cpp/actors/core/log.cpp | 28 | ||||
-rw-r--r-- | library/cpp/actors/core/log.h | 26 |
2 files changed, 47 insertions, 7 deletions
diff --git a/library/cpp/actors/core/log.cpp b/library/cpp/actors/core/log.cpp index a4427610a8..1a8880d15d 100644 --- a/library/cpp/actors/core/log.cpp +++ b/library/cpp/actors/core/log.cpp @@ -724,6 +724,13 @@ namespace NActors { TBase::WriteDirectly(TlsLogContext.Get().GetCurrentHeader()); } + TFormattedRecordWriter::~TFormattedRecordWriter() { + if (ActorContext) { + ::NActors::MemLogAdapter(*ActorContext, Priority, Component, TBase::GetResult()); + } else { + Cerr << "FALLBACK_ACTOR_LOGGING;priority=" << Priority << ";component=" << Component << ";" << TBase::GetResult() << Endl; + } + } TVerifyFormattedRecordWriter::TVerifyFormattedRecordWriter(const TString& conditionText) : ConditionText(conditionText) { @@ -737,4 +744,25 @@ namespace NActors { Y_ABORT("%s", data.data()); } + TEnsureFormattedRecordWriter::TEnsureFormattedRecordWriter(const TString& conditionText) + : ConditionText(conditionText) { + TBase::WriteDirectly(TlsLogContext.Get().GetCurrentHeader()); + TBase::Write("verification", ConditionText); + + } + + TEnsureFormattedRecordWriter::~TEnsureFormattedRecordWriter() noexcept(false) { + const TString data = TBase::GetResult(); + if (NActors::TlsActivationContext) { + ::NActors::MemLogAdapter(NActors::TlsActivationContext->AsActorContext(), NLog::EPriority::PRI_ERROR, 0, data); + } else { + Cerr << "FALLBACK_EXCEPTION_LOGGING;component=EXCEPTION;" << data << Endl; + } + if (!std::uncaught_exceptions()) { + Y_ENSURE(false, data.data()); + } else { + Y_ABORT("%s", data.data()); + } + } + } diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h index fa95b2521d..9f1d367932 100644 --- a/library/cpp/actors/core/log.h +++ b/library/cpp/actors/core/log.h @@ -514,13 +514,7 @@ namespace NActors { return *this; } - ~TFormattedRecordWriter() { - if (ActorContext) { - ::NActors::MemLogAdapter(*ActorContext, Priority, Component, TBase::GetResult()); - } else { - Cerr << "FALLBACK_ACTOR_LOGGING;priority=" << Priority << ";component=" << Component << ";" << TBase::GetResult() << Endl; - } - } + ~TFormattedRecordWriter(); }; class TVerifyFormattedRecordWriter: public TFormatedStreamWriter { @@ -539,9 +533,27 @@ namespace NActors { ~TVerifyFormattedRecordWriter(); }; + + class TEnsureFormattedRecordWriter: public TFormatedStreamWriter { + private: + using TBase = TFormatedStreamWriter; + const TString ConditionText; + public: + + TEnsureFormattedRecordWriter(const TString& conditionText); + + template <class TKey, class TValue> + TEnsureFormattedRecordWriter& operator()(const TKey& pName, const TValue& pValue) { + TBase::Write(pName, pValue); + return *this; + } + + ~TEnsureFormattedRecordWriter() noexcept(false); + }; } #define AFL_VERIFY(condition) if (condition); else NActors::TVerifyFormattedRecordWriter(#condition)("fline", TStringBuilder() << TStringBuf(__FILE__).RAfter(LOCSLASH_C) << ":" << __LINE__) +#define AFL_ENSURE(condition) if (condition); else NActors::TEnsureFormattedRecordWriter(#condition)("fline", TStringBuilder() << TStringBuf(__FILE__).RAfter(LOCSLASH_C) << ":" << __LINE__) #ifndef NDEBUG /// Assert that depend on NDEBUG macro and outputs message like printf |