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