#ifndef ERROR_ATTRIBUTES_INL_H_ #error "Direct inclusion of this file is not allowed, include error_attributes.h" // For the sake of sane code completion. #include "error_attributes.h" #endif namespace NYT { //////////////////////////////////////////////////////////////////////////////// template requires CConvertsTo T TErrorAttributes::Get(TStringBuf key) const { auto yson = GetYson(key); try { return NYT::ConvertTo(yson); } catch (const std::exception& ex) { ThrowCannotParseAttributeException(key, ex); } } template requires CConvertsTo typename TOptionalTraits::TOptional TErrorAttributes::Find(TStringBuf key) const { auto yson = FindYson(key); if (!yson) { return typename TOptionalTraits::TOptional(); } try { return NYT::ConvertTo(yson); } catch (const std::exception& ex) { ThrowCannotParseAttributeException(key, ex); } } template requires CConvertsTo T TErrorAttributes::GetAndRemove(const TKey& key) { auto result = Get(key); Remove(key); return result; } template requires CConvertsTo T TErrorAttributes::Get(TStringBuf key, const T& defaultValue) const { return Find(key).value_or(defaultValue); } template requires CConvertsTo T TErrorAttributes::GetAndRemove(const TKey& key, const T& defaultValue) { auto result = Find(key); if (result) { Remove(key); return *result; } else { return defaultValue; } } template requires CConvertsTo typename TOptionalTraits::TOptional TErrorAttributes::FindAndRemove(const TKey& key) { auto result = Find(key); if (result) { Remove(key); } return result; } template void TErrorAttributes::MergeFrom(const TDictionary& dict) { using TTraits = TMergeDictionariesTraits; for (const auto& [key, value] : TTraits::MakeIterableView(dict)) { SetYson(key, value); } } //////////////////////////////////////////////////////////////////////////////// template <> struct TMergeDictionariesTraits { static auto MakeIterableView(const TErrorAttributes& attributes) { return attributes.ListPairs(); } }; static_assert(CMergeableDictionary); //////////////////////////////////////////////////////////////////////////////// } // namespace NYT