diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-11-02 07:05:11 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2017-11-02 07:05:11 -0700 |
commit | 4e88c80a22b6ca982341413ee806ade0df57b4b7 (patch) | |
tree | 82c2daaac597f74595bc83c18646280a56898e1a /ext/librethinkdbxx/src/error.h | |
parent | a6203ed0389c1b995ebe94935b2d1ddeb01f36ee (diff) | |
download | infinitytier-4e88c80a22b6ca982341413ee806ade0df57b4b7.tar.gz infinitytier-4e88c80a22b6ca982341413ee806ade0df57b4b7.zip |
RethinkDB native connector work, minor fixes.
Diffstat (limited to 'ext/librethinkdbxx/src/error.h')
-rw-r--r-- | ext/librethinkdbxx/src/error.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/librethinkdbxx/src/error.h b/ext/librethinkdbxx/src/error.h new file mode 100644 index 00000000..ab75e248 --- /dev/null +++ b/ext/librethinkdbxx/src/error.h @@ -0,0 +1,46 @@ +#pragma once + +#include <cstdarg> +#include <cstring> +#include <string> +#include <cerrno> + +namespace RethinkDB { + +// All errors thrown by the server have this type +struct Error { + template <class ...T> + explicit Error(const char* format_, T... A) { + format(format_, A...); + } + + Error() = default; + Error(Error&&) = default; + Error(const Error&) = default; + + Error& operator= (Error&& other) { + message = std::move(other.message); + return *this; + } + + static Error from_errno(const char* str){ + return Error("%s: %s", str, strerror(errno)); + } + + // The error message + std::string message; + +private: + const size_t max_message_size = 2048; + + void format(const char* format_, ...) { + va_list args; + va_start(args, format_); + char message_[max_message_size]; + vsnprintf(message_, max_message_size, format_, args); + va_end(args); + message = message_; + } +}; + +} |