Error.h 3.6 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

#include <cstdint>
G
groot 已提交
9 10
#include <exception>
#include <string>
G
groot 已提交
11 12

namespace zilliz {
J
jinhai 已提交
13
namespace milvus {
G
groot 已提交
14 15 16 17 18 19 20 21 22 23
namespace server {

using ServerError = int32_t;

constexpr ServerError SERVER_SUCCESS = 0;

constexpr ServerError SERVER_ERROR_CODE_BASE = 0x30000;

constexpr ServerError
ToGlobalServerErrorCode(const ServerError error_code) {
G
groot 已提交
24
    return SERVER_ERROR_CODE_BASE + error_code;
G
groot 已提交
25 26
}

G
groot 已提交
27 28 29 30 31 32 33 34 35 36 37
constexpr ServerError SERVER_UNEXPECTED_ERROR = ToGlobalServerErrorCode(1);
constexpr ServerError SERVER_UNSUPPORTED_ERROR = ToGlobalServerErrorCode(2);
constexpr ServerError SERVER_NULL_POINTER = ToGlobalServerErrorCode(3);
constexpr ServerError SERVER_INVALID_ARGUMENT = ToGlobalServerErrorCode(4);
constexpr ServerError SERVER_FILE_NOT_FOUND = ToGlobalServerErrorCode(5);
constexpr ServerError SERVER_NOT_IMPLEMENT = ToGlobalServerErrorCode(6);
constexpr ServerError SERVER_BLOCKING_QUEUE_EMPTY = ToGlobalServerErrorCode(7);
constexpr ServerError SERVER_CANNOT_CREATE_FOLDER = ToGlobalServerErrorCode(8);
constexpr ServerError SERVER_CANNOT_CREATE_FILE = ToGlobalServerErrorCode(9);
constexpr ServerError SERVER_CANNOT_DELETE_FOLDER = ToGlobalServerErrorCode(10);
constexpr ServerError SERVER_CANNOT_DELETE_FILE = ToGlobalServerErrorCode(11);
P
peng.xu 已提交
38
constexpr ServerError SERVER_BUILD_INDEX_ERROR = ToGlobalServerErrorCode(12);
G
groot 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

constexpr ServerError SERVER_TABLE_NOT_EXIST = ToGlobalServerErrorCode(100);
constexpr ServerError SERVER_INVALID_TABLE_NAME = ToGlobalServerErrorCode(101);
constexpr ServerError SERVER_INVALID_TABLE_DIMENSION = ToGlobalServerErrorCode(102);
constexpr ServerError SERVER_INVALID_TIME_RANGE = ToGlobalServerErrorCode(103);
constexpr ServerError SERVER_INVALID_VECTOR_DIMENSION = ToGlobalServerErrorCode(104);
constexpr ServerError SERVER_INVALID_INDEX_TYPE = ToGlobalServerErrorCode(105);
constexpr ServerError SERVER_INVALID_ROWRECORD = ToGlobalServerErrorCode(106);
constexpr ServerError SERVER_INVALID_ROWRECORD_ARRAY = ToGlobalServerErrorCode(107);
constexpr ServerError SERVER_INVALID_TOPK = ToGlobalServerErrorCode(108);
constexpr ServerError SERVER_ILLEGAL_VECTOR_ID = ToGlobalServerErrorCode(109);
constexpr ServerError SERVER_ILLEGAL_SEARCH_RESULT = ToGlobalServerErrorCode(110);
constexpr ServerError SERVER_CACHE_ERROR = ToGlobalServerErrorCode(111);

constexpr ServerError SERVER_LICENSE_FILE_NOT_EXIST = ToGlobalServerErrorCode(500);
constexpr ServerError SERVER_LICENSE_VALIDATION_FAIL = ToGlobalServerErrorCode(501);

constexpr ServerError DB_META_TRANSACTION_FAILED = ToGlobalServerErrorCode(1000);
G
groot 已提交
57

X
xj.lin 已提交
58 59 60 61 62 63
using KnowhereError = int32_t;
constexpr KnowhereError KNOWHERE_SUCCESS = 0;
constexpr KnowhereError KNOWHERE_ERROR = ToGlobalServerErrorCode(1);
constexpr KnowhereError KNOWHERE_INVALID_ARGUMENT = ToGlobalServerErrorCode(2);
constexpr KnowhereError KNOWHERE_UNEXPECTED_ERROR = ToGlobalServerErrorCode(3);

G
groot 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
class ServerException : public std::exception {
public:
    ServerException(ServerError error_code,
              const std::string &message = std::string())
            : error_code_(error_code), message_(message) {}

public:
    ServerError error_code() const {
        return error_code_;
    }

    virtual const char *what() const noexcept {
        return message_.c_str();
    }

private:
    ServerError error_code_;
    std::string message_;
};
G
groot 已提交
83 84

}  // namespace server
J
jinhai 已提交
85
}  // namespace milvus
G
groot 已提交
86
}  // namespace zilliz