昇腾社区首页
中文
注册
开发者
下载

RegisterFormatErrorMessage

函数功能

按照规定的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'。

返回值

  • 0:成功。
  • -1:失败。

调用示例

error_msg错误码信息需按照json格式组织,error_info_list是一个包含错误信息对象的数组,至少需要包含一个元素,其中各字段含义如下:

  • errClass:错误分类。
  • errTitle:错误标题。
  • ErrCode:错误码。注意不要与当前已有的错误码重复,已有的错误码请参见故障处理中的错误码参考
  • ErrMessage:错误消息,可以包含格式化占位符(%s)。
  • Arglist:参数列表,用于说明ErrMessage中占位符对应的参数,参数列表长度与ErrMessage里格式化占位符个数必须相等。
  • suggestion:建议信息,包含:
    • Possible Cause:可能的原因。
    • 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());