Files
scylladb/redis/exceptions.hh
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

51 lines
1.6 KiB
C++

/*
* Copyright (C) 2019 pengjian.uestc @ gmail.com
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#pragma once
#include <stdexcept>
#include <seastar/core/print.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") {}
};