按照规定的json格式,调用本接口给CANN注册预定义的错误码信息后,再调用ReportPredefinedErrMsg接口上报错误码。
int32_t RegisterFormatErrorMessage(const char *error_msg, size_t error_msg_len)
同时为了方便使用,封装了宏REG_FORMAT_ERROR_MSG,用户可直接使用该宏注册,该宏直接定义静态变量注册,进程加载时就会完成注册。
#define REG_FORMAT_ERROR_MSG(error_msg, error_msg_len) \
REG_FORMAT_ERROR_MSG_UNIQ_HELPER((error_msg), (error_msg_len), __COUNTER__)
#define REG_FORMAT_ERROR_MSG_UNIQ_HELPER(error_msg, error_msg_len, counter) \
REG_FORMAT_ERROR_MSG_UNIQ((error_msg), (error_msg_len), counter)
#define REG_FORMAT_ERROR_MSG_UNIQ(error_msg, error_msg_len, counter) \
static const auto register_error_msg_##counter ATTRIBUTE_USED = []() -> int32_t { \
return error_message::RegisterFormatErrorMessage((error_msg), (error_msg_len)); \
}()
|
参数名 |
输入/输出 |
说明 |
|---|---|---|
|
error_msg |
输入 |
错误码信息,可一次注册多个错误码。 错误码信息需按json格式组织,示例请参见调用示例。 |
|
error_msg_len |
输入 |
error_msg长度,不包含末尾的'\0'。 |
error_msg错误码信息需按照json格式组织,error_info_list是一个包含错误信息对象的数组,至少需要包含一个元素,其中各字段含义如下:
#include <string>
#include "base/err_msg.h"
const std::string error_msg = R"(
{
"error_info_list":
[
{
"errClass": "GE Errors",
"errTitle": "Invalid_Dynamic_Shape_Argument",
"ErrCode": "E10018",
"ErrMessage": "Value [%s] for shape [%s] is invalid. When [--dynamic_batch_size] is included, only batch size N can be -1 in [--input_shape].",
"Arglist": "shape,index",
"suggestion": {
"Possible Cause": "When [--dynamic_batch_size] is included, only batch size N can be -1 in the shape.",
"Solution": "Try again with a valid [--input_shape] argument. Make sure that non-batch size axes are not -1."
}
},
{
"errClass": "GE Errors",
"errTitle": "Invalid_--input_shape_Argument",
"ErrCode": "E10019",
"ErrMessage": "When [--dynamic_image_size] is included, only the height and width axes can be -1 in [--input_shape].",
"Arglist": "",
"suggestion": {
"Possible Cause": "When [--dynamic_image_size] is included, only the height and width axes can be -1 in the shape.",
"Solution": "Try again with a valid [--input_shape] argument. Make sure that axes other than height and width are not -1."
}
}
]
}
)";
REG_FORMAT_ERROR_MSG(error_msg.c_str(), error_msg.size());