]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/error_code.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2017 Red Hat, Inc. <contact@redhat.com>
8 * Author: Adam C. Emerson <aemerson@redhat.com>
10 * This is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License version
12 * 2.1, as published by the Free Software Foundation. See file
16 #ifndef COMMON_CEPH_ERROR_CODE
17 #define COMMON_CEPH_ERROR_CODE
21 #include <boost/system/error_code.hpp>
22 #include <boost/asio.hpp>
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
31 // This is for error categories we define, so we can specify the
32 // equivalent integral value at the point of definition.
33 class converting_category
: public boost::system::error_category
{
35 virtual int from_code(int code
) const noexcept
= 0;
38 const boost::system::error_category
& ceph_category() noexcept
;
41 not_in_map
= 1, // The requested item was not found in the map
42 does_not_exist
, // Item does not exist
43 failure
, // An internal fault or inconsistency
44 exists
, // Already exists
45 limit_exceeded
, // Attempting to use too much of something
46 auth
, // May not be an auth failure. It could be that the
47 // preconditions to attempt auth failed.
48 conflict
, // Conflict or precondition failure
52 namespace boost::system
{
54 struct is_error_condition_enum
<::ceph::errc
> {
55 static const bool value
= true;
58 struct is_error_code_enum
<::ceph::errc
> {
59 static const bool value
= false;
64 // explicit conversion:
65 inline boost::system::error_code
make_error_code(errc e
) noexcept
{
66 return { static_cast<int>(e
), ceph_category() };
69 // implicit conversion:
70 inline boost::system::error_condition
make_error_condition(errc e
) noexcept
{
71 return { static_cast<int>(e
), ceph_category() };
74 [[nodiscard
]] boost::system::error_code
to_error_code(int ret
) noexcept
;
75 [[nodiscard
]] int from_error_code(boost::system::error_code e
) noexcept
;
77 #pragma GCC diagnostic pop
78 #pragma clang diagnostic pop
80 // Moved here from buffer.h so librados doesn't gain a dependency on
83 namespace ceph::buffer
{
84 inline namespace v15_2_0
{
85 const boost::system::error_category
& buffer_category() noexcept
;
86 enum class errc
{ bad_alloc
= 1,
92 namespace boost::system
{
94 struct is_error_code_enum
<::ceph::buffer::errc
> {
95 static const bool value
= true;
99 struct is_error_condition_enum
<::ceph::buffer::errc
> {
100 static const bool value
= false;
104 namespace ceph::buffer
{
105 inline namespace v15_2_0
{
107 // implicit conversion:
108 inline boost::system::error_code
make_error_code(errc e
) noexcept
{
109 return { static_cast<int>(e
), buffer_category() };
112 // explicit conversion:
113 inline boost::system::error_condition
114 make_error_condition(errc e
) noexcept
{
115 return { static_cast<int>(e
), buffer_category() };
118 struct error
: boost::system::system_error
{
119 using system_error::system_error
;
122 struct bad_alloc
: public error
{
123 bad_alloc() : error(errc::bad_alloc
) {}
124 bad_alloc(const char* what_arg
) : error(errc::bad_alloc
, what_arg
) {}
125 bad_alloc(const std::string
& what_arg
) : error(errc::bad_alloc
, what_arg
) {}
127 struct end_of_buffer
: public error
{
128 end_of_buffer() : error(errc::end_of_buffer
) {}
129 end_of_buffer(const char* what_arg
) : error(errc::end_of_buffer
, what_arg
) {}
130 end_of_buffer(const std::string
& what_arg
)
131 : error(errc::end_of_buffer
, what_arg
) {}
134 struct malformed_input
: public error
{
135 malformed_input() : error(errc::malformed_input
) {}
136 malformed_input(const char* what_arg
)
137 : error(errc::malformed_input
, what_arg
) {}
138 malformed_input(const std::string
& what_arg
)
139 : error(errc::malformed_input
, what_arg
) {}
141 struct error_code
: public error
{
142 error_code(int r
) : error(-r
, boost::system::system_category()) {}
143 error_code(int r
, const char* what_arg
)
144 : error(-r
, boost::system::system_category(), what_arg
) {}
145 error_code(int r
, const std::string
& what_arg
)
146 : error(-r
, boost::system::system_category(), what_arg
) {}
151 #endif // COMMON_CEPH_ERROR_CODE