summaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/issue/yql_warning.cpp
blob: 80d4686d1e569c3ecad671c4134602e97d599963 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "yql_warning.h"

#include <util/string/cast.h>
#include <util/string/join.h>


namespace NYql {

TWarningRule::EParseResult TWarningRule::ParseFrom(const TString& codePattern, const TString& action,
                                                   TWarningRule& result, TString& errorMessage)
{
    errorMessage.clear();
    result.IssueCodePattern_.clear();
    result.Action_ = EWarningAction::DEFAULT;

    if (!TryFromString<EWarningAction>(to_upper(action), result.Action_)) {
        errorMessage = "unknown warning action '" + action + "', expecting one of " +
                       Join(", ", EWarningAction::DEFAULT, EWarningAction::ERROR, EWarningAction::DISABLE);
        return EParseResult::PARSE_ACTION_FAIL;
    }

    if (codePattern != "*") {
        ui32 code;
        if (!TryFromString(codePattern, code)) {
            errorMessage = "unknown warning code '" + codePattern + "', expecting integer or '*'";
            return EParseResult::PARSE_PATTERN_FAIL;
        }
    }

    result.IssueCodePattern_ = codePattern;
    return EParseResult::PARSE_OK;
}

TWarningPolicy::TWarningPolicy(bool isReplay)
    : IsReplay_(isReplay)
{}

void TWarningPolicy::AddRule(const TWarningRule& rule)
{
    TString pattern = rule.GetPattern();
    if (pattern.empty()) {
        return;
    }

    if (pattern == "*" && IsReplay_) {
        return;
    }

    Rules_.push_back(rule);

    EWarningAction action = rule.GetAction();
    if (pattern == "*") {
        BaseAction_ = action;
        Overrides_.clear();
        return;
    }

    TIssueCode code;
    Y_ENSURE(TryFromString(pattern, code));

    if (action == BaseAction_) {
        Overrides_.erase(Overrides_.find(code));
    } else {
        Overrides_[code] = action;
    }
}

EWarningAction TWarningPolicy::GetAction(TIssueCode code) const
{
    auto it = Overrides_.find(code);
    return (it == Overrides_.end()) ? BaseAction_ : it->second;
}

void TWarningPolicy::Clear()
{
    BaseAction_ = EWarningAction::DEFAULT;
    Overrides_.clear();
    Rules_.clear();
}

}