diff --git a/parser/caffe/caffe_parser.cc b/parser/caffe/caffe_parser.cc index 51d01a5..a362763 100644 --- a/parser/caffe/caffe_parser.cc +++ b/parser/caffe/caffe_parser.cc @@ -79,6 +79,10 @@ using std::ifstream; } \ } while (0) +namespace { +const size_t kMaxErrStrLen = 128U; +} // namespace + namespace ge { graphStatus aclgrphParseCaffe(const char *model_file, const char *weights_file, ge::Graph &graph) { ErrorManager::GetInstance().SetStage(error_message::kModelCompile, error_message::kParser); @@ -256,7 +260,9 @@ Status CheckPathValid(const char *model_path, const string &custom_proto, string string &custom_proto_name) { string path_model = ge::parser::RealPath(model_path); if (path_model.empty()) { - ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, {model_path, strerror(errno)}); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, {model_path, err_msg}); GELOGE(FAILED, "[Check][Param]ModelPath %s is Invalid path of model", model_path); return FAILED; } @@ -457,24 +463,30 @@ Status CaffeModelParser::CustomProtoParse(const char *model_path, const string & Status CaffeModelParser::ReadModelWithoutWarning(const char *model_path, google::protobuf::Message *message) { int32_t copy_fd = mmDup(STDERR_FILENO); if (copy_fd < 0) { - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup] failed:%d, reason:%s", copy_fd, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup] failed:%d, reason:%s", copy_fd, err_msg); return FAILED; } int32_t fd = mmOpen(kDevNull, M_RDWR); if (fd < 0) { (void)mmClose(copy_fd); - ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {kDevNull, strerror(errno)}); - GELOGE(FAILED, "[Open][File] %s failed. reason:%s", kDevNull, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {kDevNull, err_msg}); + GELOGE(FAILED, "[Open][File] %s failed. reason:%s", kDevNull, err_msg); return FAILED; } if (mmDup2(fd, STDERR_FILENO) < 0) { (void)mmClose(fd); (void)mmClose(copy_fd); - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", err_msg); return FAILED; } @@ -488,8 +500,10 @@ Status CaffeModelParser::ReadModelWithoutWarning(const char *model_path, google: if (mmDup2(copy_fd, STDERR_FILENO) < 0) { (void)mmClose(fd); (void)mmClose(copy_fd); - REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", strerror(errno)); - GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_CALL_ERROR("E19999", "Duplicate to file STDERR_FILENO failed, errmsg:%s", err_msg); + GELOGE(FAILED, "[Invoke][Dup2] Re-orient failed. reason:%s", err_msg); return FAILED; } (void)mmClose(fd); diff --git a/parser/common/acl_graph_parser_util.cc b/parser/common/acl_graph_parser_util.cc index c3381f8..32603b2 100644 --- a/parser/common/acl_graph_parser_util.cc +++ b/parser/common/acl_graph_parser_util.cc @@ -46,6 +46,7 @@ using google::protobuf::io::ZeroCopyInputStream; using namespace ge::parser; namespace { +const size_t kMaxErrStrLen = 128U; const std::string kGraphDefaultName = "domi_default"; /// The maximum length of the file. /// Based on the security coding specification and the current actual (protobuf) model size, it is determined as 2G-1 @@ -693,16 +694,17 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY long GetFileLength(const std::s return -1, "[Check][Param] input_file path is null."); std::string real_path = RealPath(input_file.c_str()); - + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), REPORT_INPUT_ERROR("E19000", std::vector({"path", "errmsg"}), - std::vector({real_path, strerror(errno)})); + std::vector({real_path, err_msg})); return -1, "[Get][Path] input_file path '%s' not valid", input_file.c_str()); unsigned long long file_length = 0; GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(mmGetFileSize(input_file.c_str(), &file_length) != EN_OK, ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, - {input_file, strerror(errno)}); - return -1, "[Open][File] [%s] failed. %s", input_file.c_str(), strerror(errno)); + {input_file, err_msg}); + return -1, "[Open][File] [%s] failed. %s", input_file.c_str(), err_msg); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file_length == 0 || file_length > kMaxFileSizeLimit), REPORT_INPUT_ERROR( @@ -830,11 +832,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromText(const ch "[Check][Param]incorrect parameter. nullptr == file || nullptr == message"); std::string real_path = RealPath(file); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), ErrorManager::GetInstance().ATCReportErrMessage("E19000", {"path", "errmsg"}, - {file, strerror(errno)}); + {file, err_msg}); return false, "[Check][Param]Path[%s]'s realpath is empty, errmsg[%s]", file, - strerror(errno)); + err_msg); GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == -1, return false, "[Check][Param] file size not valid."); diff --git a/parser/common/model_saver.cc b/parser/common/model_saver.cc index 9af4fa8..08a7f82 100644 --- a/parser/common/model_saver.cc +++ b/parser/common/model_saver.cc @@ -25,6 +25,7 @@ #include "mmpa/mmpa_api.h" namespace { +const size_t kMaxErrStrLen = 128U; const int kFileOpSuccess = 0; } // namespace @@ -65,8 +66,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi mode_t mode = S_IRUSR | S_IWUSR; int32_t fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { - ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, strerror(errno)}); - GELOGE(FAILED, "[Open][File] [%s] failed. %s", file_path, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, err_msg}); + GELOGE(FAILED, "[Open][File] [%s] failed. %s", file_path, err_msg); return FAILED; } const char *model_char = model_str.c_str(); @@ -74,16 +77,20 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi // Write data to file mmSsize_t mmpa_ret = mmWrite(fd, const_cast((const void *)model_char), len); if (mmpa_ret == EN_ERROR || mmpa_ret == EN_INVALID_PARAM) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); ErrorManager::GetInstance().ATCReportErrMessage( - "E19004", {"file", "errmsg"}, {file_path, strerror(errno)}); + "E19004", {"file", "errmsg"}, {file_path, err_msg}); // Need to both print the error info of mmWrite and mmClose, so return ret after mmClose - GELOGE(FAILED, "[WriteTo][File] %s failed. errno = %ld, %s", file_path, mmpa_ret, strerror(errno)); + GELOGE(FAILED, "[WriteTo][File] %s failed. errno = %ld, %s", file_path, mmpa_ret, err_msg); ret = FAILED; } // Close file if (mmClose(fd) != EN_OK) { - REPORT_INNER_ERROR("E19999", "close file:%s failed. errmsg:%s", file_path, strerror(errno)); - GELOGE(FAILED, "[Close][File] %s failed. errmsg:%s", file_path, strerror(errno)); + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); + REPORT_INNER_ERROR("E19999", "close file:%s failed. errmsg:%s", file_path, err_msg); + GELOGE(FAILED, "[Close][File] %s failed. errmsg:%s", file_path, err_msg); ret = FAILED; } return ret; @@ -137,11 +144,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int ModelSaver::CreateDirectory int32_t ret = mmMkdir(tmp_dir_path, S_IRUSR | S_IWUSR | S_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); REPORT_CALL_ERROR("E19999", "Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); GELOGW("Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); return ret; } } @@ -151,11 +160,13 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int ModelSaver::CreateDirectory int32_t ret = mmMkdir(const_cast(directory_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); // 700 if (ret != 0) { if (errno != EEXIST) { + char_t err_buf[kMaxErrStrLen + 1U] = {}; + const auto err_msg = mmGetErrorFormatMessage(mmGetErrorCode(), &err_buf[0], kMaxErrStrLen); REPORT_CALL_ERROR("E19999", "Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); GELOGW("Can not create directory %s. Make sure the directory exists and writable. errmsg:%s", - directory_path.c_str(), strerror(errno)); + directory_path.c_str(), err_msg); return ret; } }