Error.h 4.9 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 24

namespace zilliz {
J
jinhai 已提交
25
namespace milvus {
G
groot 已提交
26

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

S
starlord 已提交
29 30
constexpr ErrorCode SERVER_SUCCESS = 0;
constexpr ErrorCode SERVER_ERROR_CODE_BASE = 0x30000;
S
starlord 已提交
31

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

S
starlord 已提交
37 38
constexpr ErrorCode DB_SUCCESS = 0;
constexpr ErrorCode DB_ERROR_CODE_BASE = 0x40000;
S
starlord 已提交
39

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

S
starlord 已提交
45 46
constexpr ErrorCode KNOWHERE_SUCCESS = 0;
constexpr ErrorCode KNOWHERE_ERROR_CODE_BASE = 0x50000;
S
starlord 已提交
47

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

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

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

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

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

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

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

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

J
jinhai 已提交
125
}  // namespace milvus
G
groot 已提交
126
}  // namespace zilliz