forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.hh
49 lines (39 loc) · 1.6 KB
/
exceptions.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (C) 2019 pengjian.uestc @ gmail.com
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include <seastar/core/format.hh>
#include "bytes.hh"
#include "seastarx.hh"
class redis_exception : public std::exception {
sstring _message;
public:
redis_exception(sstring message) : _message(std::move(message)) {}
virtual const char* what() const noexcept override { return _message.c_str(); }
const sstring& what_message() const noexcept { return _message; }
};
class wrong_arguments_exception : public redis_exception {
public:
wrong_arguments_exception(size_t expected, size_t given, const bytes& command)
: redis_exception(fmt::format("wrong number of arguments (given {}, expected {}) for '{}' command", given, expected, sstring(reinterpret_cast<const char*>(command.data()), command.size())))
{
}
};
class wrong_number_of_arguments_exception : public redis_exception {
public:
wrong_number_of_arguments_exception(const bytes& command)
: redis_exception(fmt::format("wrong number of arguments for '{}' command", sstring(reinterpret_cast<const char*>(command.data()), command.size())))
{
}
};
class invalid_arguments_exception : public redis_exception {
public:
invalid_arguments_exception(const bytes& command) : redis_exception(fmt::format("invalid argument for '{}' command", sstring(reinterpret_cast<const char*>(command.data()), command.size()))) {}
};
class invalid_db_index_exception : public redis_exception {
public:
invalid_db_index_exception() : redis_exception("DB index is out of range") {}
};