aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/error/error_attribute.h
blob: dec4a4dd9b3481cbe13e7803b828bbeeb0210af0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <library/cpp/yt/misc/tag_invoke_cpo.h>

// TODO(arkady-e1ppa): Eliminate.
#include <library/cpp/yt/yson_string/string.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

namespace NToAttributeValueImpl {

struct TFn
    : public TTagInvokeCpoBase<TFn>
{ };

} // namespace NToAttributeValueImpl

////////////////////////////////////////////////////////////////////////////////

inline constexpr NToAttributeValueImpl::TFn ToAttributeValue = {};

////////////////////////////////////////////////////////////////////////////////

template <class T>
concept CConvertibleToAttributeValue = CTagInvocableS<
    TTagInvokeTag<ToAttributeValue>,
    NYson::TYsonString(const T&)>;

////////////////////////////////////////////////////////////////////////////////

struct TErrorAttribute
{
    // NB(arkady-e1ppa): Switch to std::string is quite possible
    // however it requires patching IAttributeDictionary or
    // switching it to the std::string first for interop reasons.
    // Do that later.
    using TKey = TString;
    // TODO(arkady-e1ppa): Use ConvertToYsonString(value, Format::Text)
    // here for complex values. Write manual implementations as ToString
    // for primitive types (e.g. integral types, guid, string, time).
    using TValue = NYson::TYsonString;

    template <CConvertibleToAttributeValue T>
    TErrorAttribute(const TKey& key, const T& value)
        : Key(key)
        , Value(NYT::ToAttributeValue(value))
    { }

    TKey Key;
    TValue Value;
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT