• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "mindspore/core/utils/log_adapter.h"
17 #include "ErrorCode.h"
18 
GetAppErrCodeInfo(const APP_ERROR err)19 std::string GetAppErrCodeInfo(const APP_ERROR err) {
20   if ((err < APP_ERR_ACL_END) && (err >= APP_ERR_ACL_FAILURE)) {
21     return APP_ERR_ACL_LOG_STRING[((err < 0) ? (err + APP_ERR_ACL_END + 1) : err)];
22   } else if ((err < APP_ERR_COMM_END) && (err > APP_ERR_COMM_BASE)) {
23     return (err - APP_ERR_COMM_BASE) <
24                (int)sizeof(APP_ERR_COMMON_LOG_STRING) / (int)sizeof(APP_ERR_COMMON_LOG_STRING[0])
25              ? APP_ERR_COMMON_LOG_STRING[err - APP_ERR_COMM_BASE]
26              : "Undefine the error code information";
27   } else if ((err < APP_ERR_DVPP_END) && (err > APP_ERR_DVPP_BASE)) {
28     return (err - APP_ERR_DVPP_BASE) < (int)sizeof(APP_ERR_DVPP_LOG_STRING) / (int)sizeof(APP_ERR_DVPP_LOG_STRING[0])
29              ? APP_ERR_DVPP_LOG_STRING[err - APP_ERR_DVPP_BASE]
30              : "Undefine the error code information";
31   } else if ((err < APP_ERR_QUEUE_END) && (err > APP_ERR_QUEUE_BASE)) {
32     return (err - APP_ERR_QUEUE_BASE) < (int)sizeof(APP_ERR_QUEUE_LOG_STRING) / (int)sizeof(APP_ERR_QUEUE_LOG_STRING[0])
33              ? APP_ERR_QUEUE_LOG_STRING[err - APP_ERR_QUEUE_BASE]
34              : "Undefine the error code information";
35   } else {
36     return "Error code unknown";
37   }
38 }
39 
AssertErrorCode(const int code,const std::string file,const std::string function,const int line)40 void AssertErrorCode(const int code, const std::string file, const std::string function, const int line) {
41   if (code != APP_ERR_OK) {
42     MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code;
43     exit(code);
44   }
45 }
46 
CheckErrorCode(const int code,const std::string file,const std::string function,const int line)47 void CheckErrorCode(const int code, const std::string file, const std::string function, const int line) {
48   if (code != APP_ERR_OK) {
49     MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code;
50   }
51 }
52