src/error.cpp

79.2% Lines (38/48) 100.0% List of functions (7/7) 71.4% Branches (35/49)
error.cpp
f(x) Functions (7)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Mohammad Nejati
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/burl
8 //
9
10 #include <boost/burl/error.hpp>
11
12 #include <boost/http/status.hpp>
13
14 namespace boost
15 {
16 namespace burl
17 {
18
19 char const*
20 1x error_category::name() const noexcept
21 {
22 1x return "boost.burl";
23 }
24
25 std::string
26 7x error_category::message(int ev) const
27 {
28
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
7x if(ev >= 400 && ev < 600)
29 {
30 2x auto status = static_cast<http::status>(ev);
31
2/2
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
4x return "HTTP " + std::to_string(ev) + " " +
32
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
6x std::string(http::to_string(status));
33 }
34
35
5/9
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
5x switch(static_cast<error>(ev))
36 {
37 1x case error::unsupported_url_scheme:
38
1/1
✓ Branch 1 taken 1 time.
2x return "unsupported URL scheme";
39 1x case error::too_many_redirects:
40
1/1
✓ Branch 1 taken 1 time.
2x return "too many redirects";
41 1x case error::bad_redirect_response:
42
1/1
✓ Branch 1 taken 1 time.
2x return "bad redirect response";
43 1x case error::file_changed:
44
1/1
✓ Branch 1 taken 1 time.
2x return "file size changed during read";
45 case error::unsupported_proxy_scheme:
46 return "unsupported proxy scheme";
47 case error::proxy_connect_failed:
48 return "proxy could not connect to the target";
49 1x case error::proxy_auth_failed:
50
1/1
✓ Branch 1 taken 1 time.
2x return "proxy authentication failed";
51 case error::proxy_unsupported_version:
52 return "unsupported proxy protocol version";
53 default:
54 return "unknown error";
55 }
56 }
57
58 std::error_condition
59 10x error_category::default_error_condition(int ev) const noexcept
60 {
61
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
10x if(ev >= 400 && ev < 500)
62 4x return condition::client_error;
63
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
6x if(ev >= 500 && ev < 600)
64 4x return condition::server_error;
65 2x return std::error_condition(ev, *this);
66 }
67
68 //----------------------------------------------------------
69
70 char const*
71 1x condition_category::name() const noexcept
72 {
73 1x return "boost.burl.condition";
74 }
75
76 std::string
77 2x condition_category::message(int ev) const
78 {
79
2/3
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
2x switch(static_cast<condition>(ev))
80 {
81 1x case condition::client_error:
82
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP client error";
83 1x case condition::server_error:
84
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP server error";
85 default:
86 return "unknown condition";
87 }
88 }
89
90 //----------------------------------------------------------
91
92 std::error_category const&
93 38x burl_category() noexcept
94 {
95
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 34 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
38x static error_category const cat{};
96 38x return cat;
97 }
98
99 std::error_category const&
100 21x burl_condition_category() noexcept
101 {
102
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 19 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
21x static condition_category const cat{};
103 21x return cat;
104 }
105
106 } // namespace burl
107 } // namespace boost
108