Commit | Line | Data |
---|---|---|
b4953462 SM |
1 | /* |
2 | * SPDX-License-Identifier: MIT | |
3 | * | |
4 | * Copyright (c) 2022 Simon Marchi <simon.marchi@efficios.com> | |
5 | * Copyright (c) 2022 Philippe Proulx <eeppeliteloop@gmail.com> | |
6 | */ | |
7 | ||
8 | #ifndef BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP | |
9 | #define BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP | |
10 | ||
11 | #include <babeltrace2/babeltrace.h> | |
12 | #include "cfg-logging.hpp" | |
13 | ||
14 | /* | |
15 | * Appends a cause to the error of the current thread using the logging | |
16 | * configuration `_log_cfg`. | |
17 | */ | |
18 | #define BT_APPEND_CAUSE_EX(_log_cfg, _fmt, ...) \ | |
19 | do { \ | |
20 | if ((_log_cfg).selfMsgIter()) { \ | |
21 | BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR((_log_cfg).selfMsgIter(), \ | |
22 | _fmt, ##__VA_ARGS__); \ | |
23 | } else if ((_log_cfg).selfComp()) { \ | |
24 | BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT((_log_cfg).selfComp(), _fmt, \ | |
25 | ##__VA_ARGS__); \ | |
26 | } else if ((_log_cfg).selfCompCls()) { \ | |
27 | BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS((_log_cfg).selfCompCls(), \ | |
28 | _fmt, ##__VA_ARGS__); \ | |
29 | } else { \ | |
30 | BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN((_log_cfg).moduleName(), _fmt, \ | |
31 | ##__VA_ARGS__); \ | |
32 | } \ | |
33 | } while (false) | |
34 | ||
35 | #define BT_APPEND_CAUSE(_fmt, ...) BT_APPEND_CAUSE_EX((BT_CLOG_CFG), _fmt, ##__VA_ARGS__) | |
36 | ||
37 | /* | |
38 | * Appends a cause to the error of the current thread using the logging | |
39 | * configuration `_log_cfg`. | |
40 | */ | |
41 | #define BT_APPEND_CAUSE_STR_EX(_log_cfg, _str) BT_APPEND_CAUSE_EX((_log_cfg), "%s", _str) | |
42 | ||
43 | #define BT_APPEND_CAUSE_STR(_str) BT_APPEND_CAUSE_STR_EX((BT_CLOG_CFG), _str) | |
44 | ||
45 | /* | |
46 | * Appends a cause with an errno message to the error of the current | |
47 | * thread using the logging configuration `_log_cfg`. | |
48 | */ | |
49 | #define BT_APPEND_CAUSE_ERRNO_EX(_log_cfg, _init_msg, _fmt, ...) \ | |
50 | do { \ | |
51 | const auto errStr = g_strerror(errno); \ | |
52 | BT_APPEND_CAUSE_EX((_log_cfg), "%s: %s" _fmt, _init_msg, errStr, ##__VA_ARGS__); \ | |
53 | } while (false) | |
54 | ||
55 | #define BT_APPEND_CAUSE_ERRNO(_init_msg, _fmt, ...) \ | |
56 | BT_APPEND_CAUSE_EX((BT_CLOG_CFG), _init_msg, _fmt, ##__VA_ARGS__) | |
57 | ||
58 | #endif /* BABELTRACE_CPP_COMMON_CFG_ERROR_REPORTING_HPP */ |