RegisterFormatErrorMessage
Description
Registers the predefined error code information with CANN in the specified JSON format. After registration, call the ReportPredefinedErrMsg API to report error codes.
Prototype
int32_t RegisterFormatErrorMessage(const char *error_msg, size_t error_msg_len)
To facilitate usage, the macro REG_FORMAT_ERROR_MSG is encapsulated. You can directly use this macro to register error code information. The macro directly defines static variable registration, enabling the registration to complete upon process loading.
#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)); \
}()
Parameters
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
error_msg |
Input |
Error code information. Multiple error codes can be registered at a time. The error code information must be organized in JSON format. For details, see Example. |
|
error_msg_len |
Input |
Length of error_msg, excluding '\0' at the end. |
Returns
- 0: success
- -1: failure
Example
error_msg must be organized in JSON format. error_info_list is an array that contains error information objects and must contain at least one element. The fields are described as follows:
- errClass: error classification.
- errTitle: error title.
- ErrCode: error code. The error code must be different from existing ones. For details about existing error codes, see Error Codes in Troubleshooting.
- ErrMessage: error message, which can contain the formatted placeholders (%s).
- Arglist: parameter list, which describes the parameters corresponding to the placeholders in ErrMessage. The length of the parameter list must be the same as the number of formatted placeholders in ErrMessage.
- suggestion: suggestion information, including:
- Possible Cause: possible cause.
- Solution: solution.
#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());