• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.83
/libs/core/errors/src/error_code.cpp
1
//  Copyright (c) 2007-2013 Hartmut Kaiser
2
//  Copyright (c) 2011      Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#include <hpx/errors/error_code.hpp>
10
#include <hpx/errors/exception.hpp>
11

12
#include <exception>
13
#include <stdexcept>
14
#include <string>
15
#include <system_error>
16

17
///////////////////////////////////////////////////////////////////////////////
18
namespace hpx {
19
    namespace detail {
20
        class hpx_category : public std::error_category
2,411✔
21
        {
22
        public:
23
            const char* name() const noexcept
×
24
            {
25
                return "HPX";
×
26
            }
27

28
            std::string message(int value) const
99,427✔
29
            {
30
                if (value >= hpx::error::success &&
99,427✔
31
                    value < hpx::error::last_error)
99,424✔
32
                {
33
                    return std::string("HPX(") + error_names[value] +
99,424✔
34
                        ")";    //-V108
35
                }
36
                if (value & hpx::error::system_error_flag)
×
37
                {
38
                    return std::string("HPX(system_error)");
×
39
                }
40
                return "HPX(unknown_error)";
×
41
            }
99,431✔
42
        };
43

44
        struct lightweight_hpx_category : hpx_category
1,162✔
45
        {
46
        };
47

48
        // this doesn't add any text to the exception what() message
49
        class hpx_category_rethrow : public std::error_category
170✔
50
        {
51
        public:
52
            const char* name() const noexcept
×
53
            {
54
                return "";
×
55
            }
56

57
            std::string message(int) const noexcept
×
58
            {
59
                return "";
×
60
            }
×
61
        };
62

63
        struct lightweight_hpx_category_rethrow : hpx_category_rethrow
64
        {
65
        };
66
    }    // namespace detail
67

68
    ///////////////////////////////////////////////////////////////////////////
69
    std::error_category const& get_hpx_category() noexcept
4,963,030✔
70
    {
71
        static detail::hpx_category hpx_category;
4,963,030✔
72
        return hpx_category;
4,962,547✔
73
    }
74

75
    std::error_category const& get_hpx_rethrow_category() noexcept
5,496✔
76
    {
77
        static detail::hpx_category_rethrow hpx_category_rethrow;
5,496✔
78
        return hpx_category_rethrow;
5,496✔
79
    }
80

81
    std::error_category const& get_lightweight_hpx_category() noexcept
3,476,695✔
82
    {
83
        static detail::lightweight_hpx_category lightweight_hpx_category;
3,476,695✔
84
        return lightweight_hpx_category;
3,476,656✔
85
    }
86

87
    std::error_category const& get_hpx_category(throwmode mode) noexcept
6,185,346✔
88
    {
89
        switch (mode)
6,186,197✔
90
        {
91
        case throwmode::rethrow:
92
            return get_hpx_rethrow_category();
5,496✔
93

94
        case throwmode::lightweight:
95
        case throwmode::lightweight_rethrow:
96
            return get_lightweight_hpx_category();
6,180,701✔
97

98
        case throwmode::plain:
99
        default:
100
            break;
4,961,343✔
101
        }
102
        return get_hpx_category();
4,958,849✔
103
    }
6,182,655✔
104

105
    ///////////////////////////////////////////////////////////////////////////
106
    error_code::error_code(error e, throwmode mode)
91,563✔
107
      : std::error_code(make_system_error_code(e, mode))
91,568✔
108
    {
91,568✔
109
        if (e != hpx::error::success && e != hpx::error::no_success &&
91,563✔
110
            !(mode & throwmode::lightweight))
736✔
111
        {
112
            exception_ = detail::get_exception(e, "", mode);
736✔
113
        }
736✔
114
    }
91,568✔
115

116
    error_code::error_code(
×
117
        error e, char const* func, char const* file, long line, throwmode mode)
118
      : std::error_code(make_system_error_code(e, mode))
×
119
    {
×
120
        if (e != hpx::error::success && e != hpx::error::no_success &&
×
121
            !(mode & throwmode::lightweight))
×
122
        {
123
            exception_ = detail::get_exception(e, "", mode, func, file, line);
×
124
        }
×
125
    }
×
126

127
    error_code::error_code(error e, char const* msg, throwmode mode)
×
128
      : std::error_code(make_system_error_code(e, mode))
×
129
    {
×
130
        if (e != hpx::error::success && e != hpx::error::no_success &&
×
131
            !(mode & throwmode::lightweight))
×
132
        {
133
            exception_ = detail::get_exception(e, msg, mode);
×
134
        }
×
135
    }
×
136

137
    error_code::error_code(error e, char const* msg, char const* func,
×
138
        char const* file, long line, throwmode mode)
139
      : std::error_code(make_system_error_code(e, mode))
×
140
    {
×
141
        if (e != hpx::error::success && e != hpx::error::no_success &&
×
142
            !(mode & throwmode::lightweight))
×
143
        {
144
            exception_ = detail::get_exception(e, msg, mode, func, file, line);
×
145
        }
×
146
    }
×
147

148
    error_code::error_code(error e, std::string const& msg, throwmode mode)
×
149
      : std::error_code(make_system_error_code(e, mode))
×
150
    {
×
151
        if (e != hpx::error::success && e != hpx::error::no_success &&
×
152
            !(mode & throwmode::lightweight))
×
153
        {
154
            exception_ = detail::get_exception(e, msg, mode);
×
155
        }
×
156
    }
×
157

158
    error_code::error_code(error e, std::string const& msg, char const* func,
6,296✔
159
        char const* file, long line, throwmode mode)
160
      : std::error_code(make_system_error_code(e, mode))
6,296✔
161
    {
6,296✔
162
        if (e != hpx::error::success && e != hpx::error::no_success &&
6,296✔
163
            !(mode & throwmode::lightweight))
6,296✔
164
        {
165
            exception_ = detail::get_exception(e, msg, mode, func, file, line);
32✔
166
        }
32✔
167
    }
6,296✔
168

169
    error_code::error_code(int err, hpx::exception const& e)
2,589✔
170
    {
2,589✔
171
        this->std::error_code::assign(err, get_hpx_category());
2,589✔
172
        exception_ = std::make_exception_ptr(e);
2,589✔
173
    }
2,589✔
174

175
    error_code::error_code(std::exception_ptr const& e)
5,496✔
176
      : std::error_code(
5,496✔
177
            make_system_error_code(get_error(e), throwmode::rethrow))
5,496✔
178
      , exception_(e)
5,496✔
179
    {
5,496✔
180
    }
5,496✔
181

182
    ///////////////////////////////////////////////////////////////////////////
183
    std::string error_code::get_message() const
×
184
    {
185
        if (exception_)
×
186
        {
187
            try
188
            {
189
                std::rethrow_exception(exception_);
×
190
            }
×
191
            catch (std::exception const& be)
192
            {
193
                return be.what();
×
194
            }
×
195
        }
×
196
        return get_error_what(*this);    // provide at least minimal error text
×
197
    }
×
198

199
    ///////////////////////////////////////////////////////////////////////////
200
    error_code::error_code(error_code const& rhs)
×
201
      : std::error_code(rhs.value() == hpx::error::success ?
×
202
                make_success_code(
×
203
                    (category() == get_lightweight_hpx_category()) ?
×
204
                        hpx::throwmode::lightweight :
205
                        hpx::throwmode::plain) :
206
                rhs)
×
207
      , exception_(rhs.exception_)
×
208
    {
×
209
    }
×
210

211
    ///////////////////////////////////////////////////////////////////////////
212
    error_code& error_code::operator=(error_code const& rhs)
2,257,121✔
213
    {
214
        if (this != &rhs)
2,257,122✔
215
        {
216
            if (rhs.value() == hpx::error::success)
2,257,070✔
217
            {
218
                // if the rhs is a success code, we maintain our throw mode
219
                this->std::error_code::operator=(make_success_code(
4,490,556✔
220
                    (category() == get_lightweight_hpx_category()) ?
2,245,312✔
221
                        hpx::throwmode::lightweight :
222
                        hpx::throwmode::plain));
223
            }
2,245,312✔
224
            else
225
            {
226
                this->std::error_code::operator=(rhs);
11,792✔
227
            }
228
            exception_ = rhs.exception_;
2,257,104✔
229
        }
2,257,104✔
230
        return *this;
2,257,107✔
231
    }
232
    /// \endcond
233
}    // namespace hpx
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc