blob: 3e251628594108230ba470b0a09e7b35ca691a36 (
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
|
#pragma once
#include <yt/cpp/mapreduce/interface/errors.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
///
/// @brief RAII guard that sets a predicate for identifying "expected" errors.
///
/// Can be used for logging: If predicate is set, log errors at Info level instead of Error.
class TExpectedErrorGuard {
public:
using TErrorPredicate = std::function<bool(const TErrorResponse&)>;
explicit TExpectedErrorGuard(const TErrorPredicate& predicate);
~TExpectedErrorGuard();
TExpectedErrorGuard(const TExpectedErrorGuard&) = delete;
TExpectedErrorGuard& operator=(const TExpectedErrorGuard&) = delete;
static bool IsErrorExpected(const TErrorResponse& error);
/// @brief Release current predicate, restore previously saved predicate.
void Release();
private:
TErrorPredicate PreviousPredicate_;
bool Released_ = false;
static TErrorPredicate& GetCurrentPredicate();
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|