1 /**
2 * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
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 /*!
18 * \file error_util.cpp
19 * \brief
20 */
21 #include <map>
22 #include "error_util.h"
23 #include "error_code.h"
24 #include "op_log.h"
25
26 using namespace std;
27 using namespace ge;
28
29 namespace ge {
GetViewErrorCodeStr(ge::ViewErrorCode errCode)30 std::string GetViewErrorCodeStr(ge::ViewErrorCode errCode) { return "E" + std::to_string(errCode); }
31
GetShapeErrMsg(uint32_t index,const std::string & wrong_shape,const std::string & correct_shape)32 std::string GetShapeErrMsg(uint32_t index, const std::string &wrong_shape, const std::string &correct_shape) {
33 std::string msg = ConcatString(index, "th input has wrong shape", wrong_shape, ", it should be ", correct_shape);
34 return msg;
35 }
36
GetAttrValueErrMsg(const std::string & attr_name,const std::string & wrong_val,const std::string & correct_val)37 std::string GetAttrValueErrMsg(const std::string &attr_name, const std::string &wrong_val,
38 const std::string &correct_val) {
39 std::string msg = ConcatString("attr[", attr_name, "], has wrong value[", wrong_val, "], it should be ", correct_val);
40 return msg;
41 }
42
GetAttrSizeErrMsg(const std::string & attr_name,const std::string & wrong_size,const std::string & correct_size)43 std::string GetAttrSizeErrMsg(const std::string &attr_name, const std::string &wrong_size,
44 const std::string &correct_size) {
45 std::string msg =
46 ConcatString("attr[", attr_name, "], has wrong size[", wrong_size, "], it should be ", correct_size);
47 return msg;
48 }
49
GetInputInvalidErrMsg(const std::string & param_name)50 std::string GetInputInvalidErrMsg(const std::string ¶m_name) {
51 std::string msg = ConcatString("get ", param_name, " failed");
52 return msg;
53 }
54
GetShapeSizeErrMsg(uint32_t index,const std::string & wrong_shape_size,const std::string & correct_shape_size)55 std::string GetShapeSizeErrMsg(uint32_t index, const std::string &wrong_shape_size,
56 const std::string &correct_shape_size) {
57 std::string msg =
58 ConcatString(index, "th input has wrong shape size ", wrong_shape_size, ", it should be ", correct_shape_size);
59 return msg;
60 }
61
GetInputFormatNotSupportErrMsg(const std::string & param_name,const std::string & expected_format_list,const std::string & data_format)62 std::string GetInputFormatNotSupportErrMsg(const std::string ¶m_name, const std::string &expected_format_list,
63 const std::string &data_format) {
64 std::string msg =
65 ConcatString("[", param_name, "], has wrong format [", data_format, "], it should be in ", expected_format_list);
66 return msg;
67 }
68
GetInputDtypeNotSupportErrMsg(const std::string & param_name,const std::string & expected_dtype_list,const std::string & data_dtype)69 std::string GetInputDtypeNotSupportErrMsg(const std::string ¶m_name, const std::string &expected_dtype_list,
70 const std::string &data_dtype) {
71 std::string msg =
72 ConcatString("[", param_name, "], has wrong dtype [", data_dtype, "], it should be in ", expected_dtype_list);
73 return msg;
74 }
75
GetInputDTypeErrMsg(const std::string & param_name,const std::string & expected_dtype,const std::string & data_dtype)76 std::string GetInputDTypeErrMsg(const std::string ¶m_name, const std::string &expected_dtype,
77 const std::string &data_dtype) {
78 std::string msg =
79 ConcatString("[", param_name, "], has wrong dtype [", data_dtype, "], it should be ", expected_dtype);
80 return msg;
81 }
82
GetInputFormatErrMsg(const std::string & param_name,const std::string & expected_format,const std::string & data_format)83 std::string GetInputFormatErrMsg(const std::string ¶m_name, const std::string &expected_format,
84 const std::string &data_format) {
85 std::string msg =
86 ConcatString("[", param_name, "], has wrong format [", data_format, "], it should be in ", expected_format);
87 return msg;
88 }
89
SetAttrErrMsg(const std::string & param_name)90 std::string SetAttrErrMsg(const std::string ¶m_name) {
91 std::string msg = ConcatString("set param [", param_name, "] failed");
92 return msg;
93 }
94
UpdateParamErrMsg(const std::string & param_name)95 std::string UpdateParamErrMsg(const std::string ¶m_name) {
96 std::string msg = ConcatString("update [", param_name, "] failed");
97 return msg;
98 }
99
GetParamOutRangeErrMsg(const std::string & param_name,const std::string & range,const std::string & real_value)100 std::string GetParamOutRangeErrMsg(const std::string ¶m_name, const std::string &range,
101 const std::string &real_value) {
102 std::string msg = ConcatString("the parameter [", param_name, "] should be in the range of [", range,
103 "], but actually is ", real_value);
104 return msg;
105 }
106
OtherErrMsg(const std::string & error_detail)107 std::string OtherErrMsg(const std::string &error_detail) {
108 std::string msg = error_detail;
109 return msg;
110 }
111 } // namespace ge
112