1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. 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 | * \author Hongqing.hu |
17 | * \date Nov 2020 |
18 | * \brief Interface of Bilin Error |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include <map> |
24 | |
25 | namespace proxima { |
26 | namespace be { |
27 | |
28 | /*! Error |
29 | */ |
30 | class ErrorCode { |
31 | public: |
32 | /*! Error Code |
33 | */ |
34 | class Code { |
35 | public: |
36 | //! Constructor |
37 | Code(int val, const char *str) : value_(-val), desc_(str) { |
38 | ErrorCode::Instance()->emplace(this); |
39 | } |
40 | |
41 | //! Retrieve the value of code |
42 | operator int() const { |
43 | return (this->value_); |
44 | } |
45 | |
46 | //! Retrieve the value of code |
47 | int value() const { |
48 | return (this->value_); |
49 | } |
50 | |
51 | //! Retrieve the description of code |
52 | const char *desc() const { |
53 | return (this->desc_); |
54 | } |
55 | |
56 | private: |
57 | int value_; |
58 | const char *desc_; |
59 | }; |
60 | |
61 | //! Retrieve the description of code |
62 | static const char *What(int val); |
63 | |
64 | protected: |
65 | //! Constructor |
66 | ErrorCode(void) : map_() {} |
67 | |
68 | //! Inserts a new code into map |
69 | void emplace(const ErrorCode::Code *code) { |
70 | map_.emplace(code->value(), code); |
71 | } |
72 | |
73 | //! Retrieve the description of code |
74 | const char *what(int val) const { |
75 | auto iter = map_.find(val); |
76 | if (iter != map_.end()) { |
77 | return iter->second->desc(); |
78 | } |
79 | return "" ; |
80 | } |
81 | |
82 | //! Retrieve the singleton |
83 | static ErrorCode *Instance(void) { |
84 | static ErrorCode error; |
85 | return (&error); |
86 | } |
87 | |
88 | private: |
89 | //! Disable them |
90 | ErrorCode(const ErrorCode &) = delete; |
91 | ErrorCode(ErrorCode &&) = delete; |
92 | ErrorCode &operator=(const ErrorCode &) = delete; |
93 | |
94 | //! Error code map |
95 | std::map<int, const ErrorCode::Code *> map_; |
96 | }; |
97 | |
98 | //! Error Code Define |
99 | #define PROXIMA_BE_ERROR_CODE_DEFINE(__NAME__, __VAL__, __DESC__) \ |
100 | const proxima::be::ErrorCode::Code ErrorCode_##__NAME__((__VAL__), \ |
101 | (__DESC__)); \ |
102 | const proxima::be::ErrorCode::Code &_ErrorCode_##__VAL__##_Register( \ |
103 | ErrorCode_##__NAME__) |
104 | |
105 | //! Proxima BE Error Code Declare |
106 | #define PROXIMA_BE_ERROR_CODE_DECLARE(__NAME__) \ |
107 | extern const proxima::be::ErrorCode::Code ErrorCode_##__NAME__ |
108 | |
109 | //! Error code helper |
110 | #define PROXIMA_BE_ERROR_CODE(__NAME__) proxima::be::ErrorCode_##__NAME__ |
111 | |
112 | |
113 | // 0~999 [Builtin] |
114 | PROXIMA_BE_ERROR_CODE_DECLARE(Success); |
115 | |
116 | |
117 | // 1000~1999 [Common Error] |
118 | PROXIMA_BE_ERROR_CODE_DECLARE(RuntimeError); |
119 | PROXIMA_BE_ERROR_CODE_DECLARE(LogicError); |
120 | PROXIMA_BE_ERROR_CODE_DECLARE(StatusError); |
121 | PROXIMA_BE_ERROR_CODE_DECLARE(LoadConfig); |
122 | PROXIMA_BE_ERROR_CODE_DECLARE(ConfigError); |
123 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidArgument); |
124 | PROXIMA_BE_ERROR_CODE_DECLARE(NotInitialized); |
125 | PROXIMA_BE_ERROR_CODE_DECLARE(OpenFile); |
126 | PROXIMA_BE_ERROR_CODE_DECLARE(ReadData); |
127 | PROXIMA_BE_ERROR_CODE_DECLARE(WriteData); |
128 | PROXIMA_BE_ERROR_CODE_DECLARE(ExceedLimit); |
129 | PROXIMA_BE_ERROR_CODE_DECLARE(SerializeError); |
130 | PROXIMA_BE_ERROR_CODE_DECLARE(DerializeError); |
131 | PROXIMA_BE_ERROR_CODE_DECLARE(StartServer); |
132 | PROXIMA_BE_ERROR_CODE_DECLARE(StoppedService); |
133 | |
134 | // 2000~2999 [Format Check] |
135 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyCollectionName); |
136 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyColumnName); |
137 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyColumns); |
138 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyRepositoryTable); |
139 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyRepositoryName); |
140 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyUserName); |
141 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyPassword); |
142 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidURI); |
143 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidCollectionStatus); |
144 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRecord); |
145 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidQuery); |
146 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidIndexDataFormat); |
147 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidWriteRequest); |
148 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidVectorFormat); |
149 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRepositoryType); |
150 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidDataType); |
151 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidIndexType); |
152 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidSegment); |
153 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRevision); |
154 | PROXIMA_BE_ERROR_CODE_DECLARE(InvalidFeature); |
155 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedSchema); |
156 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedMagicNumber); |
157 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedIndexColumn); |
158 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedForward); |
159 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedDimension); |
160 | PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedDataType); |
161 | |
162 | // 3000~3999 [Meta] |
163 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateStatusField); |
164 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateRevisionField); |
165 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateCollectionUIDField); |
166 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateIndexTypeField); |
167 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateDataTypeField); |
168 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateParametersField); |
169 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateRepositoryTypeField); |
170 | PROXIMA_BE_ERROR_CODE_DECLARE(UpdateColumnNameField); |
171 | PROXIMA_BE_ERROR_CODE_DECLARE(ZeroDocsPerSegment); |
172 | PROXIMA_BE_ERROR_CODE_DECLARE(UnsupportedConnection); |
173 | |
174 | // 4000~4999 [Index] |
175 | PROXIMA_BE_ERROR_CODE_DECLARE(DuplicateCollection); |
176 | PROXIMA_BE_ERROR_CODE_DECLARE(DuplicateKey); |
177 | PROXIMA_BE_ERROR_CODE_DECLARE(InexistentCollection); |
178 | PROXIMA_BE_ERROR_CODE_DECLARE(InexistentColumn); |
179 | PROXIMA_BE_ERROR_CODE_DECLARE(InexistentKey); |
180 | PROXIMA_BE_ERROR_CODE_DECLARE(SuspendedCollection); |
181 | PROXIMA_BE_ERROR_CODE_DECLARE(LostSegment); |
182 | PROXIMA_BE_ERROR_CODE_DECLARE(EmptyLsnContext); |
183 | PROXIMA_BE_ERROR_CODE_DECLARE(ExceedRateLimit); |
184 | |
185 | // 5000~5999 [Query] |
186 | PROXIMA_BE_ERROR_CODE_DECLARE(UnavailableSegment); |
187 | PROXIMA_BE_ERROR_CODE_DECLARE(OutOfBoundsResult); |
188 | PROXIMA_BE_ERROR_CODE_DECLARE(UnreadyQueue); |
189 | PROXIMA_BE_ERROR_CODE_DECLARE(ScheduleError); |
190 | PROXIMA_BE_ERROR_CODE_DECLARE(UnreadableCollection); |
191 | PROXIMA_BE_ERROR_CODE_DECLARE(TaskIsRunning); |
192 | |
193 | // NOTICE |
194 | // 10000~19999 [SDK] |
195 | // 20000~29999 [Repository] |
196 | |
197 | } // end namespace be |
198 | } // end namespace proxima |
199 | |