Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef ADUMP_ERROR_MANAGER_H
11 : #define ADUMP_ERROR_MANAGER_H
12 : #include <string>
13 : #include <vector>
14 : #include "base/err_msg.h"
15 : #include "str_utils.h"
16 : #include "log/adx_log.h"
17 :
18 : namespace Adx {
19 : // REPORT_PREDEFINED_ERR_MSG takes std::vector<const char *>, while the REPORT_EP000x_* macros below
20 : // pass std::vector<std::string>. Converting here keeps those macros unchanged.
21 1254 : inline std::vector<const char *> ToCStrVec(const std::vector<std::string> &in)
22 : {
23 1254 : std::vector<const char *> out;
24 1254 : out.reserve(in.size());
25 5262 : for (const auto &s : in) {
26 4008 : out.emplace_back(s.c_str());
27 : }
28 1254 : return out;
29 0 : }
30 : } // namespace Adx
31 :
32 : // Named locals before c_str(): every caller builds the vectors inline as temporaries. Binding them
33 : // to the do/while block makes the lifetime explicit rather than relying on full-expression scope.
34 : #define ADUMP_INPUT_ERROR(error_code, key, value) \
35 : do { \
36 : const std::vector<std::string> adumpErrKeys__ = (key); \
37 : const std::vector<std::string> adumpErrVals__ = (value); \
38 : REPORT_PREDEFINED_ERR_MSG((error_code), \
39 : Adx::ToCStrVec(adumpErrKeys__), \
40 : Adx::ToCStrVec(adumpErrVals__)); \
41 : } while (0)
42 :
43 : namespace Adx {
44 :
45 : #define ADUMP_TO_CSTR(s) (std::string(s).c_str())
46 :
47 : // EP0004 Parse Error Report Macro - Inline for performance
48 : #define REPORT_EP0004_PARSE_ERROR(moduleName, reason, configPath) \
49 : do { \
50 : IDE_LOGE("[%s] Parse failed: %s", moduleName, ADUMP_TO_CSTR(reason)); \
51 : ADUMP_INPUT_ERROR("EP0004", std::vector<std::string>({"path", "reason"}), \
52 : std::vector<std::string>({configPath, reason})); \
53 : } while (0)
54 :
55 : // EP0001 Configuration Item Error Report Macro - Inline for performance
56 : #define REPORT_EP0001_ITEM_ERROR(moduleName, item, reason, configPath) \
57 : do { \
58 : IDE_LOGE("[%s] The content of configuration item %s in config file %s is invalid. Reason: %s", \
59 : moduleName, ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(reason)); \
60 : ADUMP_INPUT_ERROR("EP0001", std::vector<std::string>({"item", "path", "reason"}), \
61 : std::vector<std::string>({item, configPath, reason})); \
62 : } while (0)
63 :
64 : // EP0002 Enum Value Invalid Report Macro - Inline for performance
65 : #define REPORT_EP0002_ENUM_VALUE_INVALID(moduleName, value, item, expectedValue, configPath) \
66 : do { \
67 : IDE_LOGE("[%s] Value %s for configuration item %s in file %s is invalid, must be selected from [%s].", \
68 : moduleName, ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(expectedValue)); \
69 : ADUMP_INPUT_ERROR("EP0002", std::vector<std::string>({"value", "item", "path", "expected_value"}), \
70 : std::vector<std::string>({value, item, configPath, expectedValue})); \
71 : } while (0)
72 :
73 : // EP0003 Value Invalid Report Macro - Inline for performance
74 : #define REPORT_EP0003_INVALID_VALUE(moduleName, value, item, reason, configPath) \
75 : do { \
76 : IDE_LOGE("[%s] Value %s for parameter %s in config file %s is invalid. Reason: %s", \
77 : moduleName, ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(reason)); \
78 : ADUMP_INPUT_ERROR("EP0003", std::vector<std::string>({"value", "item", "path", "reason"}), \
79 : std::vector<std::string>({value, item, configPath, reason})); \
80 : } while (0)
81 :
82 : // EP0005 Conflict Report Macros - Inline for performance
83 : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_SET(moduleName, errorItem, conditionItem, configPath) \
84 : do { \
85 : std::string reason = StrUtils::Format( \
86 : ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_SET, \
87 : ADUMP_TO_CSTR(errorItem), ADUMP_TO_CSTR(conditionItem)); \
88 : IDE_LOGE("[%s] %s", moduleName, reason.c_str()); \
89 : ADUMP_INPUT_ERROR("EP0005", std::vector<std::string>({"path", "reason"}), \
90 : std::vector<std::string>({configPath, reason})); \
91 : } while (0)
92 :
93 : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_VALUE(moduleName, errorItem, conditionItem, conditionValue, configPath) \
94 : do { \
95 : std::string reason = StrUtils::Format( \
96 : ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_VALUE, \
97 : ADUMP_TO_CSTR(conditionItem), ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem)); \
98 : IDE_LOGE("[%s] %s", moduleName, reason.c_str()); \
99 : ADUMP_INPUT_ERROR("EP0005", std::vector<std::string>({"path", "reason"}), \
100 : std::vector<std::string>({configPath, reason})); \
101 : } while (0)
102 :
103 : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE(moduleName, errorItem, conditionItem, conditionValue, configPath) \
104 : do { \
105 : std::string reason = StrUtils::Format( \
106 : ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE, \
107 : ADUMP_TO_CSTR(conditionItem), ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem)); \
108 : IDE_LOGE("[%s] %s", moduleName, reason.c_str()); \
109 : ADUMP_INPUT_ERROR("EP0005", std::vector<std::string>({"path", "reason"}), \
110 : std::vector<std::string>({configPath, reason})); \
111 : } while (0)
112 :
113 : #define REPORT_EP0005_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE(moduleName, errorItem, errorValue, conditionItem, conditionValue, configPath) \
114 : do { \
115 : std::string reason = StrUtils::Format( \
116 : ADUMP_REASON_FMT_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE, \
117 : ADUMP_TO_CSTR(conditionItem), ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem), ADUMP_TO_CSTR(errorValue)); \
118 : IDE_LOGE("[%s] %s", moduleName, reason.c_str()); \
119 : ADUMP_INPUT_ERROR("EP0005", std::vector<std::string>({"path", "reason"}), \
120 : std::vector<std::string>({configPath, reason})); \
121 : } while (0)
122 :
123 : #define REPORT_EP0006_INVALID_ARGUMENT(funcName, value, param, reason) \
124 : do { \
125 : IDE_LOGE("[%s] %s failed. Value %s for parameter %s is invalid. Reason: %s", \
126 : ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(param), ADUMP_TO_CSTR(reason)); \
127 : ADUMP_INPUT_ERROR("EP0006", std::vector<std::string>({"func", "value", "param", "reason"}), \
128 : std::vector<std::string>({funcName, value, param, reason})); \
129 : } while (0)
130 :
131 : #define REPORT_EP0007_NULL_POINTER(funcName, param) \
132 : do { \
133 : IDE_LOGE("[%s] %s failed because %s cannot be a NULL pointer.", \
134 : ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(param)); \
135 : ADUMP_INPUT_ERROR("EP0007", std::vector<std::string>({"func", "param"}), \
136 : std::vector<std::string>({funcName, param})); \
137 : } while (0)
138 :
139 : #define REPORT_EP0008_API_CALL_SEQUENCE(funcName, reason) \
140 : do { \
141 : IDE_LOGE("[%s] %s failed. Reason: %s.", ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(reason)); \
142 : ADUMP_INPUT_ERROR("EP0008", std::vector<std::string>({"func", "reason"}), \
143 : std::vector<std::string>({std::string(funcName), std::string(reason)})); \
144 : } while (0)
145 :
146 : // EP0001 Reasons - Configuration item problems
147 : constexpr const char* ADUMP_REASON_ITEM_NOT_FOUND = "The configuration item is not found";
148 : constexpr const char* ADUMP_REASON_ITEM_VALUE_EMPTY = "The configuration item value is empty";
149 : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_STRING = "This configuration item must be of the string type";
150 : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_ARRAY = "This configuration item must be of the array type";
151 : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_OBJECT = "This configuration item must be of the object type";
152 : constexpr const char* ADUMP_REASON_MEMBER_MUST_BE_STRING = "The member type of this configuration item must be string";
153 : constexpr const char* ADUMP_REASON_MEMBER_MUST_BE_OBJECT = "The member type of this configuration item must be object";
154 :
155 : // EP0003 Reasons - Value validity problems
156 : constexpr const char* ADUMP_REASON_VALUE_INVALID_CHARS = "The value contains invalid characters";
157 : constexpr const char* ADUMP_REASON_PATH_NOT_EXIST = "The path does not exist";
158 : constexpr const char* ADUMP_REASON_PATH_NO_PERMISSION = "The value is a path without read and write permissions";
159 : constexpr const char* ADUMP_REASON_PATH_INVALID = "The value is an invalid path";
160 : constexpr const char* ADUMP_REASON_PATH_NOT_DIRECTORY = "The path is not a directory path";
161 : constexpr const char* ADUMP_REASON_PATH_LENGTH_EXCEED_LIMIT =
162 : "The path length exceeds the maximum limit of 512 characters";
163 : constexpr const char* ADUMP_REASON_DUMP_STEP_EXCEED_LIMIT =
164 : "The value exceeds the maximum limit of 100 intervals";
165 : constexpr const char* ADUMP_REASON_DUMP_STEP_INVALID_FORMAT =
166 : "The value has invalid format, expected format: 5-10";
167 : constexpr const char* ADUMP_REASON_DUMP_STEP_NOT_DIGIT =
168 : "The value contains non-digit characters, expected format: 1 or 5-10";
169 : constexpr const char* ADUMP_REASON_DUMP_STEP_INVALID_RANGE =
170 : "The value has invalid format, start step must not exceed end step, expected format: 5-10";
171 : constexpr const char* ADUMP_REASON_BLACKLIST_SIZE_EXCEED_LIMIT =
172 : "The value size exceeds the maximum limit of 100";
173 : constexpr const char* ADUMP_REASON_BLACKLIST_POS_INVALID_FORMAT =
174 : "The value has invalid format, the prefix must be input or output, expected format: inputn or outputn";
175 : constexpr const char* ADUMP_REASON_BLACKLIST_POS_INDEX_NOT_DIGIT =
176 : "The value has invalid format, the index must be a digit, expected format: input1 or output1";
177 : constexpr const char* ADUMP_REASON_OPNAME_RANGE_INCOMPLETE =
178 : "The item is incomplete, begin and end must be configured together and non-empty";
179 :
180 : // EP0005 Reason Templates - Configuration conflict
181 : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_SET =
182 : "Configuration items %s and %s cannot be configured";
183 : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_VALUE =
184 : "When configuration item %s is set to %s, configuration item %s cannot be configured";
185 : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE =
186 : "When configuration item %s is not set to %s, configuration item %s cannot be configured";
187 : constexpr const char* ADUMP_REASON_FMT_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE =
188 : "When configuration item %s is set to %s, configuration item %s cannot be set to %s";
189 :
190 : // EP0006 Reasons - Invalid argument problems
191 : constexpr const char* ADUMP_REASON_RESERVED_PARAM_MUST_EQUAL = "The parameter is reserved and can only be %s";
192 : constexpr const char* ADUMP_REASON_PARAM_PATH_EMPTY = "The parameter is a path and cannot be empty";
193 : constexpr const char* ADUMP_REASON_PARAM_PATH_HAS_PARENT_DIR =
194 : "The parameter is a relative path and cannot contain '..' segment";
195 : constexpr const char* ADUMP_REASON_PARAM_PATH_CREATE_DIR_ERROR =
196 : "The parameter is a path and the path fails to be created. Error: %s";
197 : constexpr const char* ADUMP_REASON_PARAM_PATH_NOT_DIRECTORY =
198 : "The parameter is not a directory path";
199 : constexpr const char* ADUMP_REASON_PARAM_MUST_BE_GREATER_THAN = "The parameter must be greater than %s";
200 : constexpr const char* ADUMP_REASON_BUFFER_SIZE_NOT_ENOUGH = "The buffer size %s is not enough for the result size %s";
201 : constexpr const char* ADUMP_REASON_PARAM_VALUE_EXCEED_LIMIT = "The value %s exceeds the maximum limit of %s";
202 : constexpr const char* ADUMP_REASON_PARAM_VALUE_NOT_SUPPORTED = "The value %s is not supported, it must be %s";
203 :
204 : // EP0008 Reasons - Call API sequence
205 : constexpr const char* ADUMP_REASON_API_CALLED_REPEATEDLY = "This API cannot be called repeatedly";
206 : constexpr const char* ADUMP_REASON_EXCEPTION_DUMP_NOT_ENABLED = "Exception Dump must be enabled before %s is called";
207 :
208 : constexpr const char* FUNC_NAME_ACL_OP_START_DUMP_ARGS = "aclopStartDumpArgs";
209 : constexpr const char* FUNC_ACL_OP_START_DUMP_ARGS_PARAM_PATH = "path";
210 : constexpr const char* FUNC_ACL_OP_START_DUMP_ARGS_PARAM_DUMPTYPE = "dumpType";
211 : constexpr const char* FUNC_NAME_ACL_DUMP_REG_CALLBACK = "acldumpRegCallback";
212 : constexpr const char* FUNC_ACL_DUMP_REG_CALLBACK_PARAM_CLBK = "messageCallback";
213 : constexpr const char* FUNC_ACL_DUMP_REG_CALLBACK_PARAM_FLAG = "flag";
214 : constexpr const char* FUNC_NAME_ACL_DUMP_SAVE_EXCEPTION_INFO = "acldumpSaveExceptionInfo";
215 : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_FILENAME = "fileName";
216 : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_TENSORS = "tensors";
217 : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_TENSORCOUNT = "tensorCount";
218 : constexpr const char* FUNC_NAME_ACL_DUMP_GET_EXCEPTION_INFO_PATH = "acldumpGetExceptionInfoPath";
219 : constexpr const char* FUNC_ACL_DUMP_GET_EXCEPTION_INFO_PATH_PARAM_PATH = "path";
220 : constexpr const char* FUNC_ACL_DUMP_GET_EXCEPTION_INFO_PATH_PARAM_MAXLEN = "maxLen";
221 : } // namespace Adx
222 :
223 : #endif
|