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
25namespace proxima {
26namespace be {
27
28/*! Error
29 */
30class 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]
114PROXIMA_BE_ERROR_CODE_DECLARE(Success);
115
116
117// 1000~1999 [Common Error]
118PROXIMA_BE_ERROR_CODE_DECLARE(RuntimeError);
119PROXIMA_BE_ERROR_CODE_DECLARE(LogicError);
120PROXIMA_BE_ERROR_CODE_DECLARE(StatusError);
121PROXIMA_BE_ERROR_CODE_DECLARE(LoadConfig);
122PROXIMA_BE_ERROR_CODE_DECLARE(ConfigError);
123PROXIMA_BE_ERROR_CODE_DECLARE(InvalidArgument);
124PROXIMA_BE_ERROR_CODE_DECLARE(NotInitialized);
125PROXIMA_BE_ERROR_CODE_DECLARE(OpenFile);
126PROXIMA_BE_ERROR_CODE_DECLARE(ReadData);
127PROXIMA_BE_ERROR_CODE_DECLARE(WriteData);
128PROXIMA_BE_ERROR_CODE_DECLARE(ExceedLimit);
129PROXIMA_BE_ERROR_CODE_DECLARE(SerializeError);
130PROXIMA_BE_ERROR_CODE_DECLARE(DerializeError);
131PROXIMA_BE_ERROR_CODE_DECLARE(StartServer);
132PROXIMA_BE_ERROR_CODE_DECLARE(StoppedService);
133
134// 2000~2999 [Format Check]
135PROXIMA_BE_ERROR_CODE_DECLARE(EmptyCollectionName);
136PROXIMA_BE_ERROR_CODE_DECLARE(EmptyColumnName);
137PROXIMA_BE_ERROR_CODE_DECLARE(EmptyColumns);
138PROXIMA_BE_ERROR_CODE_DECLARE(EmptyRepositoryTable);
139PROXIMA_BE_ERROR_CODE_DECLARE(EmptyRepositoryName);
140PROXIMA_BE_ERROR_CODE_DECLARE(EmptyUserName);
141PROXIMA_BE_ERROR_CODE_DECLARE(EmptyPassword);
142PROXIMA_BE_ERROR_CODE_DECLARE(InvalidURI);
143PROXIMA_BE_ERROR_CODE_DECLARE(InvalidCollectionStatus);
144PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRecord);
145PROXIMA_BE_ERROR_CODE_DECLARE(InvalidQuery);
146PROXIMA_BE_ERROR_CODE_DECLARE(InvalidIndexDataFormat);
147PROXIMA_BE_ERROR_CODE_DECLARE(InvalidWriteRequest);
148PROXIMA_BE_ERROR_CODE_DECLARE(InvalidVectorFormat);
149PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRepositoryType);
150PROXIMA_BE_ERROR_CODE_DECLARE(InvalidDataType);
151PROXIMA_BE_ERROR_CODE_DECLARE(InvalidIndexType);
152PROXIMA_BE_ERROR_CODE_DECLARE(InvalidSegment);
153PROXIMA_BE_ERROR_CODE_DECLARE(InvalidRevision);
154PROXIMA_BE_ERROR_CODE_DECLARE(InvalidFeature);
155PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedSchema);
156PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedMagicNumber);
157PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedIndexColumn);
158PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedForward);
159PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedDimension);
160PROXIMA_BE_ERROR_CODE_DECLARE(MismatchedDataType);
161
162// 3000~3999 [Meta]
163PROXIMA_BE_ERROR_CODE_DECLARE(UpdateStatusField);
164PROXIMA_BE_ERROR_CODE_DECLARE(UpdateRevisionField);
165PROXIMA_BE_ERROR_CODE_DECLARE(UpdateCollectionUIDField);
166PROXIMA_BE_ERROR_CODE_DECLARE(UpdateIndexTypeField);
167PROXIMA_BE_ERROR_CODE_DECLARE(UpdateDataTypeField);
168PROXIMA_BE_ERROR_CODE_DECLARE(UpdateParametersField);
169PROXIMA_BE_ERROR_CODE_DECLARE(UpdateRepositoryTypeField);
170PROXIMA_BE_ERROR_CODE_DECLARE(UpdateColumnNameField);
171PROXIMA_BE_ERROR_CODE_DECLARE(ZeroDocsPerSegment);
172PROXIMA_BE_ERROR_CODE_DECLARE(UnsupportedConnection);
173
174// 4000~4999 [Index]
175PROXIMA_BE_ERROR_CODE_DECLARE(DuplicateCollection);
176PROXIMA_BE_ERROR_CODE_DECLARE(DuplicateKey);
177PROXIMA_BE_ERROR_CODE_DECLARE(InexistentCollection);
178PROXIMA_BE_ERROR_CODE_DECLARE(InexistentColumn);
179PROXIMA_BE_ERROR_CODE_DECLARE(InexistentKey);
180PROXIMA_BE_ERROR_CODE_DECLARE(SuspendedCollection);
181PROXIMA_BE_ERROR_CODE_DECLARE(LostSegment);
182PROXIMA_BE_ERROR_CODE_DECLARE(EmptyLsnContext);
183PROXIMA_BE_ERROR_CODE_DECLARE(ExceedRateLimit);
184
185// 5000~5999 [Query]
186PROXIMA_BE_ERROR_CODE_DECLARE(UnavailableSegment);
187PROXIMA_BE_ERROR_CODE_DECLARE(OutOfBoundsResult);
188PROXIMA_BE_ERROR_CODE_DECLARE(UnreadyQueue);
189PROXIMA_BE_ERROR_CODE_DECLARE(ScheduleError);
190PROXIMA_BE_ERROR_CODE_DECLARE(UnreadableCollection);
191PROXIMA_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