Error.h 5.2 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
J
jinhai 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
J
jinhai 已提交
11

G
groot 已提交
12 13 14
#pragma once

#include <cstdint>
G
groot 已提交
15 16
#include <exception>
#include <string>
G
groot 已提交
17

J
jinhai 已提交
18
namespace milvus {
G
groot 已提交
19

S
starlord 已提交
20
using ErrorCode = int32_t;
G
groot 已提交
21

S
starlord 已提交
22
constexpr ErrorCode SERVER_SUCCESS = 0;
23
constexpr ErrorCode SERVER_ERROR_CODE_BASE = 30000;
S
starlord 已提交
24

S
starlord 已提交
25 26
constexpr ErrorCode
ToServerErrorCode(const ErrorCode error_code) {
G
groot 已提交
27
    return SERVER_ERROR_CODE_BASE + error_code;
G
groot 已提交
28 29
}

S
starlord 已提交
30
constexpr ErrorCode DB_SUCCESS = 0;
31
constexpr ErrorCode DB_ERROR_CODE_BASE = 40000;
S
starlord 已提交
32

S
starlord 已提交
33
constexpr ErrorCode
S
starlord 已提交
34 35
ToDbErrorCode(const ErrorCode error_code) {
    return DB_ERROR_CODE_BASE + error_code;
S
starlord 已提交
36
}
G
groot 已提交
37

S
starlord 已提交
38
constexpr ErrorCode KNOWHERE_SUCCESS = 0;
39
constexpr ErrorCode KNOWHERE_ERROR_CODE_BASE = 50000;
S
starlord 已提交
40

S
starlord 已提交
41 42 43 44
constexpr ErrorCode
ToKnowhereErrorCode(const ErrorCode error_code) {
    return KNOWHERE_ERROR_CODE_BASE + error_code;
}
G
groot 已提交
45

46 47 48 49 50 51 52 53
constexpr ErrorCode WAL_SUCCESS = 0;
constexpr ErrorCode WAL_ERROR_CODE_BASE = 60000;

constexpr ErrorCode
ToWalErrorCode(const ErrorCode error_code) {
    return WAL_ERROR_CODE_BASE + error_code;
}

S
starlord 已提交
54
// server error code
S
starlord 已提交
55 56 57 58 59 60 61 62 63 64 65
constexpr ErrorCode SERVER_UNEXPECTED_ERROR = ToServerErrorCode(1);
constexpr ErrorCode SERVER_UNSUPPORTED_ERROR = ToServerErrorCode(2);
constexpr ErrorCode SERVER_NULL_POINTER = ToServerErrorCode(3);
constexpr ErrorCode SERVER_INVALID_ARGUMENT = ToServerErrorCode(4);
constexpr ErrorCode SERVER_FILE_NOT_FOUND = ToServerErrorCode(5);
constexpr ErrorCode SERVER_NOT_IMPLEMENT = ToServerErrorCode(6);
constexpr ErrorCode SERVER_CANNOT_CREATE_FOLDER = ToServerErrorCode(8);
constexpr ErrorCode SERVER_CANNOT_CREATE_FILE = ToServerErrorCode(9);
constexpr ErrorCode SERVER_CANNOT_DELETE_FOLDER = ToServerErrorCode(10);
constexpr ErrorCode SERVER_CANNOT_DELETE_FILE = ToServerErrorCode(11);
constexpr ErrorCode SERVER_BUILD_INDEX_ERROR = ToServerErrorCode(12);
J
Jin Hai 已提交
66
constexpr ErrorCode SERVER_CANNOT_OPEN_FILE = ToServerErrorCode(13);
S
starlord 已提交
67

G
groot 已提交
68 69 70
constexpr ErrorCode SERVER_COLLECTION_NOT_EXIST = ToServerErrorCode(100);
constexpr ErrorCode SERVER_INVALID_COLLECTION_NAME = ToServerErrorCode(101);
constexpr ErrorCode SERVER_INVALID_COLLECTION_DIMENSION = ToServerErrorCode(102);
S
starlord 已提交
71 72 73 74 75 76 77
constexpr ErrorCode SERVER_INVALID_VECTOR_DIMENSION = ToServerErrorCode(104);
constexpr ErrorCode SERVER_INVALID_INDEX_TYPE = ToServerErrorCode(105);
constexpr ErrorCode SERVER_INVALID_ROWRECORD = ToServerErrorCode(106);
constexpr ErrorCode SERVER_INVALID_ROWRECORD_ARRAY = ToServerErrorCode(107);
constexpr ErrorCode SERVER_INVALID_TOPK = ToServerErrorCode(108);
constexpr ErrorCode SERVER_ILLEGAL_VECTOR_ID = ToServerErrorCode(109);
constexpr ErrorCode SERVER_ILLEGAL_SEARCH_RESULT = ToServerErrorCode(110);
S
starlord 已提交
78
constexpr ErrorCode SERVER_CACHE_FULL = ToServerErrorCode(111);
S
starlord 已提交
79 80 81 82 83
constexpr ErrorCode SERVER_WRITE_ERROR = ToServerErrorCode(112);
constexpr ErrorCode SERVER_INVALID_NPROBE = ToServerErrorCode(113);
constexpr ErrorCode SERVER_INVALID_INDEX_NLIST = ToServerErrorCode(114);
constexpr ErrorCode SERVER_INVALID_INDEX_METRIC_TYPE = ToServerErrorCode(115);
constexpr ErrorCode SERVER_INVALID_INDEX_FILE_SIZE = ToServerErrorCode(116);
84
constexpr ErrorCode SERVER_OUT_OF_MEMORY = ToServerErrorCode(117);
85
constexpr ErrorCode SERVER_INVALID_PARTITION_TAG = ToServerErrorCode(118);
S
starlord 已提交
86

S
starlord 已提交
87
// db error code
S
starlord 已提交
88 89 90 91 92
constexpr ErrorCode DB_META_TRANSACTION_FAILED = ToDbErrorCode(1);
constexpr ErrorCode DB_ERROR = ToDbErrorCode(2);
constexpr ErrorCode DB_NOT_FOUND = ToDbErrorCode(3);
constexpr ErrorCode DB_ALREADY_EXIST = ToDbErrorCode(4);
constexpr ErrorCode DB_INVALID_PATH = ToDbErrorCode(5);
93
constexpr ErrorCode DB_INCOMPATIB_META = ToDbErrorCode(6);
94
constexpr ErrorCode DB_INVALID_META_URI = ToDbErrorCode(7);
G
groot 已提交
95
constexpr ErrorCode DB_EMPTY_COLLECTION = ToDbErrorCode(8);
96
constexpr ErrorCode DB_BLOOM_FILTER_ERROR = ToDbErrorCode(9);
T
Tinkerrr 已提交
97
constexpr ErrorCode PARTITION_NOT_FOUND = ToDbErrorCode(10);
S
starlord 已提交
98

S
starlord 已提交
99
// knowhere error code
S
starlord 已提交
100 101 102
constexpr ErrorCode KNOWHERE_ERROR = ToKnowhereErrorCode(1);
constexpr ErrorCode KNOWHERE_INVALID_ARGUMENT = ToKnowhereErrorCode(2);
constexpr ErrorCode KNOWHERE_UNEXPECTED_ERROR = ToKnowhereErrorCode(3);
103
constexpr ErrorCode KNOWHERE_NO_SPACE = ToKnowhereErrorCode(4);
X
xj.lin 已提交
104

105 106 107 108 109 110
// knowhere error code
constexpr ErrorCode WAL_ERROR = ToWalErrorCode(1);
constexpr ErrorCode WAL_META_ERROR = ToWalErrorCode(2);
constexpr ErrorCode WAL_FILE_ERROR = ToWalErrorCode(3);
constexpr ErrorCode WAL_PATH_ERROR = ToWalErrorCode(4);

S
starlord 已提交
111
namespace server {
S
starlord 已提交
112 113
class ServerException : public std::exception {
 public:
S
starlord 已提交
114
    explicit ServerException(ErrorCode error_code, const std::string& message = std::string())
S
starlord 已提交
115 116 117 118
        : error_code_(error_code), message_(message) {
    }

 public:
S
starlord 已提交
119 120
    ErrorCode
    error_code() const {
S
starlord 已提交
121 122 123
        return error_code_;
    }

S
starlord 已提交
124 125
    virtual const char*
    what() const noexcept {
S
starlord 已提交
126 127 128 129 130 131 132
        return message_.c_str();
    }

 private:
    ErrorCode error_code_;
    std::string message_;
};
S
starlord 已提交
133
}  // namespace server
G
groot 已提交
134

J
jinhai 已提交
135
}  // namespace milvus