100.00% Lines (3/3) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2026 Michael Vandeberg 3   // Copyright (c) 2026 Michael Vandeberg
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/capy 8   // Official repository: https://github.com/cppalliance/capy
9   // 9   //
10   10  
11   #ifndef BOOST_CAPY_ERROR_HPP 11   #ifndef BOOST_CAPY_ERROR_HPP
12   #define BOOST_CAPY_ERROR_HPP 12   #define BOOST_CAPY_ERROR_HPP
13   13  
14   #include <boost/capy/detail/config.hpp> 14   #include <boost/capy/detail/config.hpp>
15   #include <system_error> 15   #include <system_error>
16   16  
17   namespace boost { 17   namespace boost {
18   namespace capy { 18   namespace capy {
19   19  
20 - /** Error codes for capy I/O operations. 20 + /** Identify failures reported by capy algorithms and I/O operations.
21   21  
22 - These codes are produced by capy algorithms and I/O operations. 22 + Capy algorithms and I/O operations produce these codes.
23   23  
24   @warning Callers must never compare received `error_code` values 24   @warning Callers must never compare received `error_code` values
25   directly against this enum. Always compare against the portable 25   directly against this enum. Always compare against the portable
26   @ref cond error conditions instead. These enum values are 26   @ref cond error conditions instead. These enum values are
27 - implementation details subject to change. 27 + implementation details subject to change. The exception is
  28 + `test_failure`, which has no @ref cond equivalent and is compared
  29 + directly.
28   30  
29   @see @ref cond 31   @see @ref cond
30   */ 32   */
31   enum class error 33   enum class error
32   { 34   {
33   /// End-of-stream reached. Compare with `cond::eof`. 35   /// End-of-stream reached. Compare with `cond::eof`.
34   eof = 1, 36   eof = 1,
35   37  
36 - /// Operation was cancelled. Compare with `cond::canceled`. 38 + /// Operation was canceled. Compare with `cond::canceled`.
37   canceled, 39   canceled,
38   40  
39   /// Internal test assertion failed. 41   /// Internal test assertion failed.
40   test_failure, 42   test_failure,
41   43  
42   /// Peer closed connection without proper TLS shutdown. 44   /// Peer closed connection without proper TLS shutdown.
43   /// Compare with `cond::stream_truncated`. 45   /// Compare with `cond::stream_truncated`.
44   stream_truncated, 46   stream_truncated,
45   47  
46   /// Operation timed out. Compare with `cond::timeout`. 48   /// Operation timed out. Compare with `cond::timeout`.
47   timeout 49   timeout
48   }; 50   };
49   51  
50   } // capy 52   } // capy
51   } // boost 53   } // boost
52   54  
53   namespace std { 55   namespace std {
54   template<> 56   template<>
55   struct is_error_code_enum< 57   struct is_error_code_enum<
56   ::boost::capy::error> 58   ::boost::capy::error>
57   : std::true_type {}; 59   : std::true_type {};
58   } // std 60   } // std
59   61  
60   namespace boost { 62   namespace boost {
61   namespace capy { 63   namespace capy {
62   64  
63   namespace detail { 65   namespace detail {
64   66  
65   struct BOOST_CAPY_SYMBOL_VISIBLE 67   struct BOOST_CAPY_SYMBOL_VISIBLE
66   error_cat_type 68   error_cat_type
67   : std::error_category 69   : std::error_category
68   { 70   {
69   BOOST_CAPY_DECL const char* name( 71   BOOST_CAPY_DECL const char* name(
70   ) const noexcept override; 72   ) const noexcept override;
71   BOOST_CAPY_DECL std::string message( 73   BOOST_CAPY_DECL std::string message(
72   int) const override; 74   int) const override;
73   BOOST_CAPY_DECL std::error_condition default_error_condition( 75   BOOST_CAPY_DECL std::error_condition default_error_condition(
74   int) const noexcept override; 76   int) const noexcept override;
75   constexpr error_cat_type() noexcept = default; 77   constexpr error_cat_type() noexcept = default;
76   }; 78   };
77   79  
78   BOOST_CAPY_DECL extern error_cat_type error_cat; 80   BOOST_CAPY_DECL extern error_cat_type error_cat;
79   81  
80   } // detail 82   } // detail
81   83  
82   /** Create an error_code from an error value. 84   /** Create an error_code from an error value.
83   85  
84   @param ev The library error value. 86   @param ev The library error value.
85   87  
86   @return An `std::error_code` holding `ev` in the library's 88   @return An `std::error_code` holding `ev` in the library's
87   error category. 89   error category.
88   */ 90   */
89   inline 91   inline
90   std::error_code 92   std::error_code
HITCBC 91   3472 make_error_code( 93   3703 make_error_code(
92   error ev) noexcept 94   error ev) noexcept
93   { 95   {
HITCBC 94   3472 return std::error_code{ 96   3703 return std::error_code{
95   static_cast<std::underlying_type< 97   static_cast<std::underlying_type<
96   error>::type>(ev), 98   error>::type>(ev),
HITCBC 97   3472 detail::error_cat}; 99   3703 detail::error_cat};
98   } 100   }
99   101  
100   } // capy 102   } // capy
101   } // boost 103   } // boost
102   104  
103   #endif 105   #endif