Error.h 4.7 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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
//
//   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.

G
groot 已提交
18 19 20
#pragma once

#include <cstdint>
G
groot 已提交
21 22
#include <exception>
#include <string>
G
groot 已提交
23

J
jinhai 已提交
24
namespace milvus {
G
groot 已提交
25

S
starlord 已提交
26
using ErrorCode = int32_t;
G
groot 已提交
27

S
starlord 已提交
28
constexpr ErrorCode SERVER_SUCCESS = 0;
29
constexpr ErrorCode SERVER_ERROR_CODE_BASE = 30000;
S
starlord 已提交
30

S
starlord 已提交
31 32
constexpr ErrorCode
ToServerErrorCode(const ErrorCode error_code) {
G
groot 已提交
33
    return SERVER_ERROR_CODE_BASE + error_code;
G
groot 已提交
34 35
}

S
starlord 已提交
36
constexpr ErrorCode DB_SUCCESS = 0;
37
constexpr ErrorCode DB_ERROR_CODE_BASE = 40000;
S
starlord 已提交
38

S
starlord 已提交
39
constexpr ErrorCode
S
starlord 已提交
40 41
ToDbErrorCode(const ErrorCode error_code) {
    return DB_ERROR_CODE_BASE + error_code;
S
starlord 已提交
42
}
G
groot 已提交
43

S
starlord 已提交
44
constexpr ErrorCode KNOWHERE_SUCCESS = 0;
45
constexpr ErrorCode KNOWHERE_ERROR_CODE_BASE = 50000;
S
starlord 已提交
46

S
starlord 已提交
47 48 49 50
constexpr ErrorCode
ToKnowhereErrorCode(const ErrorCode error_code) {
    return KNOWHERE_ERROR_CODE_BASE + error_code;
}
G
groot 已提交
51

S
starlord 已提交
52
// server error code
S
starlord 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
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 已提交
76
constexpr ErrorCode SERVER_CACHE_FULL = ToServerErrorCode(111);
S
starlord 已提交
77 78 79 80 81
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);
82
constexpr ErrorCode SERVER_OUT_OF_MEMORY = ToServerErrorCode(117);
S
starlord 已提交
83

S
starlord 已提交
84
// db error code
S
starlord 已提交
85 86 87 88 89
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);
90
constexpr ErrorCode DB_INCOMPATIB_META = ToDbErrorCode(6);
91
constexpr ErrorCode DB_INVALID_META_URI = ToDbErrorCode(7);
S
starlord 已提交
92

S
starlord 已提交
93
// knowhere error code
S
starlord 已提交
94 95 96
constexpr ErrorCode KNOWHERE_ERROR = ToKnowhereErrorCode(1);
constexpr ErrorCode KNOWHERE_INVALID_ARGUMENT = ToKnowhereErrorCode(2);
constexpr ErrorCode KNOWHERE_UNEXPECTED_ERROR = ToKnowhereErrorCode(3);
97
constexpr ErrorCode KNOWHERE_NO_SPACE = ToKnowhereErrorCode(4);
X
xj.lin 已提交
98

S
starlord 已提交
99
namespace server {
S
starlord 已提交
100 101
class ServerException : public std::exception {
 public:
S
starlord 已提交
102
    explicit ServerException(ErrorCode error_code, const std::string& message = std::string())
S
starlord 已提交
103 104 105 106
        : error_code_(error_code), message_(message) {
    }

 public:
S
starlord 已提交
107 108
    ErrorCode
    error_code() const {
S
starlord 已提交
109 110 111
        return error_code_;
    }

S
starlord 已提交
112 113
    virtual const char*
    what() const noexcept {
S
starlord 已提交
114 115 116 117 118 119 120
        return message_.c_str();
    }

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

J
jinhai 已提交
123
}  // namespace milvus