From 61d41cf099d9385e321124c70ab36a3c5463f1fa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 9 Oct 2018 15:18:14 +0800 Subject: [PATCH] crimson/auth: add domain specific error types Signed-off-by: Kefu Chai --- src/crimson/auth/Errors.cc | 31 +++++++++++++++++++++++++++++++ src/crimson/auth/Errors.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/crimson/auth/Errors.cc create mode 100644 src/crimson/auth/Errors.h diff --git a/src/crimson/auth/Errors.cc b/src/crimson/auth/Errors.cc new file mode 100644 index 00000000000..c5f1b8d89f3 --- /dev/null +++ b/src/crimson/auth/Errors.cc @@ -0,0 +1,31 @@ +#include "Errors.h" + +namespace ceph::net { + +const std::error_category& auth_category() +{ + struct category : public std::error_category { + const char* name() const noexcept override { + return "ceph::auth"; + } + + std::string message(int ev) const override { + switch (static_cast(ev)) { + case error::success: + return "success", + case error::key_not_found: + return "key not found"; + case error::invalid_key: + return "corrupted key"; + case error::unknown_service: + return "unknown service"; + default: + return "unknown"; + } + } + }; + static category instance; + return instance; +} + +} // namespace ceph::auth diff --git a/src/crimson/auth/Errors.h b/src/crimson/auth/Errors.h new file mode 100644 index 00000000000..92f5c733c2f --- /dev/null +++ b/src/crimson/auth/Errors.h @@ -0,0 +1,37 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +namespace ceph::auth { + +enum class error { + success = 0, + key_not_found, + invalid_key, + unknown_service, // no ticket handler for required service +}; + +const std::error_category& auth_category(); + +inline std::error_code make_error_code(error e) +{ + return {static_cast(e), auth_category()}; +} + +inline std::error_condition make_error_condition(error e) +{ + return {static_cast(e), auth_category()}; +} + +class auth_error : public std::runtime_error {}; + +} // namespace ceph::auth + +namespace std { + +/// enables implicit conversion to std::error_condition +template <> +struct is_error_condition_enum : public true_type {}; + +} // namespace std -- 2.39.5