Error.h 4.5 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

S
starlord 已提交
46
// server error code
S
starlord 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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);

constexpr ErrorCode SERVER_TABLE_NOT_EXIST = ToServerErrorCode(100);
constexpr ErrorCode SERVER_INVALID_TABLE_NAME = ToServerErrorCode(101);
constexpr ErrorCode SERVER_INVALID_TABLE_DIMENSION = ToServerErrorCode(102);
constexpr ErrorCode SERVER_INVALID_TIME_RANGE = ToServerErrorCode(103);
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 已提交
70
constexpr ErrorCode SERVER_CACHE_FULL = ToServerErrorCode(111);
S
starlord 已提交
71 72 73 74 75
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);
76
constexpr ErrorCode SERVER_OUT_OF_MEMORY = ToServerErrorCode(117);
S
starlord 已提交
77

S
starlord 已提交
78
// db error code
S
starlord 已提交
79 80 81 82 83
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);
84
constexpr ErrorCode DB_INCOMPATIB_META = ToDbErrorCode(6);
85
constexpr ErrorCode DB_INVALID_META_URI = ToDbErrorCode(7);
S
starlord 已提交
86

S
starlord 已提交
87
// knowhere error code
S
starlord 已提交
88 89 90
constexpr ErrorCode KNOWHERE_ERROR = ToKnowhereErrorCode(1);
constexpr ErrorCode KNOWHERE_INVALID_ARGUMENT = ToKnowhereErrorCode(2);
constexpr ErrorCode KNOWHERE_UNEXPECTED_ERROR = ToKnowhereErrorCode(3);
91
constexpr ErrorCode KNOWHERE_NO_SPACE = ToKnowhereErrorCode(4);
X
xj.lin 已提交
92

S
starlord 已提交
93
namespace server {
S
starlord 已提交
94 95
class ServerException : public std::exception {
 public:
S
starlord 已提交
96
    explicit ServerException(ErrorCode error_code, const std::string& message = std::string())
S
starlord 已提交
97 98 99 100
        : error_code_(error_code), message_(message) {
    }

 public:
S
starlord 已提交
101 102
    ErrorCode
    error_code() const {
S
starlord 已提交
103 104 105
        return error_code_;
    }

S
starlord 已提交
106 107
    virtual const char*
    what() const noexcept {
S
starlord 已提交
108 109 110 111 112 113 114
        return message_.c_str();
    }

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

J
jinhai 已提交
117
}  // namespace milvus