src/error.cpp
56.2% Lines (27/48)
100.0% List of functions (7/7)
49.0% Branches (24/49)
Functions (7)
Function
Calls
Lines
Branches
Blocks
boost::burl::error_category::name() const
:20
1x
100.0%
–
100.0%
boost::burl::error_category::message[abi:cxx11](int) const
:26
2x
20.8%
25.9%
18.0%
boost::burl::error_category::default_error_condition(int) const
:59
10x
100.0%
87.5%
100.0%
boost::burl::condition_category::name() const
:71
1x
100.0%
–
100.0%
boost::burl::condition_category::message[abi:cxx11](int) const
:77
2x
75.0%
66.7%
50.0%
boost::burl::burl_category()
:93
33x
100.0%
75.0%
100.0%
boost::burl::burl_condition_category()
:100
21x
100.0%
75.0%
100.0%
| 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 | 2x | error_category::message(int ev) const | ||
| 27 | { | |||
| 28 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2x | 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 | ✗ | switch(static_cast<error>(ev)) | ||
| 36 | { | |||
| 37 | ✗ | case error::unsupported_url_scheme: | ||
| 38 | ✗ | return "unsupported URL scheme"; | ||
| 39 | ✗ | case error::too_many_redirects: | ||
| 40 | ✗ | return "too many redirects"; | ||
| 41 | ✗ | case error::bad_redirect_response: | ||
| 42 | ✗ | return "bad redirect response"; | ||
| 43 | ✗ | case error::file_changed: | ||
| 44 | ✗ | 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 | ✗ | case error::proxy_auth_failed: | ||
| 50 | ✗ | 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 | 33x | burl_category() noexcept | ||
| 94 | { | |||
| 95 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 29 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
33x | static error_category const cat{}; | |
| 96 | 33x | 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 |