LCOV - code coverage report
Current view: top level - source/error - error.cpp (source / functions) Coverage Total Hit
Test: mxlib Lines: 91.5 % 59 54
Test Date: 2026-08-30 22:23:37 Functions: 100.0 % 20 20

            Line data    Source code
       1              : /** \file error.cpp
       2              :  * \author Jared R. Males (jaredmales@gmail.com)
       3              :  * \brief Definitions for the mxlib error reporting system.
       4              :  * \ingroup error_handling_files
       5              :  *
       6              :  */
       7              : 
       8              : //***********************************************************************//
       9              : // Copyright 2025 Jared R. Males (jaredmales@gmail.com)
      10              : //
      11              : // This file is part of mxlib.
      12              : //
      13              : // mxlib is free software: you can redistribute it and/or modify
      14              : // it under the terms of the GNU General Public License as published by
      15              : // the Free Software Foundation, either version 3 of the License, or
      16              : // (at your option) any later version.
      17              : //
      18              : // mxlib is distributed in the hope that it will be useful,
      19              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      20              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21              : // GNU General Public License for more details.
      22              : //
      23              : // You should have received a copy of the GNU General Public License
      24              : // along with mxlib.  If not, see <http://www.gnu.org/licenses/>.
      25              : //***********************************************************************//
      26              : 
      27              : #include "error/error.hpp"
      28              : #include <format>
      29              : 
      30              : namespace mx
      31              : {
      32              : 
      33              : namespace internal
      34              : {
      35              : 
      36              : template <>
      37            2 : std::string mxlib_error_message<verbose::o>( [[maybe_unused]] const error_t &code,
      38              :                                              [[maybe_unused]] const std::string &expl,
      39              :                                              [[maybe_unused]] const std::source_location &loc )
      40              : {
      41            4 :     return "";
      42              : }
      43              : 
      44              : template <>
      45           10 : std::string mxlib_error_message<verbose::v>( const error_t &code,
      46              :                                              const std::string &expl,
      47              :                                              [[maybe_unused]] const std::source_location &loc )
      48              : {
      49           10 :     return std::format( "{}: {}.", errorName( code ), expl );
      50              : }
      51              : 
      52              : template <>
      53              : std::string
      54          282 : mxlib_error_message<verbose::vv>( const error_t &code, const std::string &expl, const std::source_location &loc )
      55              : {
      56              :     return std::format( "{} ({}): {}. [{} {}]",
      57            0 :                         errorMessage( code ),
      58          282 :                         errorName( code ),
      59              :                         expl,
      60          282 :                         loc.file_name(),
      61          564 :                         loc.line() );
      62              : }
      63              : 
      64              : template <>
      65              : std::string
      66            3 : mxlib_error_message<verbose::vvv>( const error_t &code, const std::string &expl, const std::source_location &loc )
      67              : {
      68              :     return std::format( "An error has occurred in mxlib:\n"
      69              :                         "        error: {} ({})\n"
      70              :                         "  explanation: {}\n"
      71              :                         "      in file: {}\n"
      72              :                         "      at line: {}\n"
      73              :                         "       source: {}\n",
      74            0 :                         errorMessage( code ),
      75            3 :                         errorName( code ),
      76              :                         expl,
      77            3 :                         loc.file_name(),
      78            3 :                         loc.line(),
      79            6 :                         loc.function_name() );
      80              : }
      81              : 
      82              : template <>
      83            2 : std::string mxlib_error_message<verbose::o>( const error_t &code, [[maybe_unused]] const std::source_location &loc )
      84              : {
      85            4 :     return "";
      86              : }
      87              : 
      88              : template <>
      89            6 : std::string mxlib_error_message<verbose::v>( const error_t &code, [[maybe_unused]] const std::source_location &loc )
      90              : {
      91           12 :     return errorName( code );
      92              : }
      93              : 
      94              : template <>
      95           93 : std::string mxlib_error_message<verbose::vv>( const error_t &code, const std::source_location &loc )
      96              : {
      97           93 :     return std::format( "{} ({}). [{} {}]", errorMessage( code ), errorName( code ), loc.file_name(), loc.line() );
      98              : }
      99              : 
     100              : template <>
     101            3 : std::string mxlib_error_message<verbose::vvv>( const error_t &code, const std::source_location &loc )
     102              : {
     103              :     return std::format( "An error has occurred in mxlib:\n"
     104              :                         "        error: {} ({})\n"
     105              :                         "      in file: {}\n"
     106              :                         "      at line: {}\n"
     107              :                         "       source: {}\n",
     108            0 :                         errorMessage( code ),
     109            3 :                         errorName( code ),
     110            3 :                         loc.file_name(),
     111            3 :                         loc.line(),
     112            6 :                         loc.function_name() );
     113              : }
     114              : 
     115              : template <>
     116           14 : error_t mxlib_error_report<verbose::o>( const error_t &code,
     117              :                                         [[maybe_unused]] const std::string &expl,
     118              :                                         [[maybe_unused]] const std::source_location &loc )
     119              : {
     120           14 :     return code;
     121              : }
     122              : 
     123              : template <>
     124            2 : error_t mxlib_error_report<verbose::o>( const error_t &code, [[maybe_unused]] const std::source_location &loc )
     125              : {
     126            2 :     return code;
     127              : }
     128              : 
     129              : 
     130              : } // namespace internal
     131              : 
     132              : template <>
     133            3 : std::string error_message<verbose::o>( const error_t &code,
     134              :                                        [[maybe_unused]] const std::string &expl,
     135              :                                        [[maybe_unused]] const std::source_location &loc )
     136              : {
     137            6 :     return "";
     138              : }
     139              : 
     140              : template <>
     141            3 : std::string error_message<verbose::v>( const error_t &code, const std::string &expl, const std::source_location &loc )
     142              : {
     143            3 :     return internal::mxlib_error_message<verbose::v>( code, expl, loc );
     144              : }
     145              : 
     146              : template <>
     147           20 : std::string error_message<verbose::vv>( const error_t &code, const std::string &expl, const std::source_location &loc )
     148              : {
     149           20 :     return internal::mxlib_error_message<verbose::vv>( code, expl, loc );
     150              : }
     151              : 
     152              : template <>
     153            3 : std::string error_message<verbose::vvv>( const error_t &code, const std::string &expl, const std::source_location &loc )
     154              : {
     155              :     return std::format( "An error has occurred:\n"
     156              :                         "        error: {} ({})\n"
     157              :                         "  explanation: {}\n"
     158              :                         "      in file: {}\n"
     159              :                         "      at line: {}\n"
     160              :                         "       source: {}\n",
     161            0 :                         errorMessage( code ),
     162            3 :                         errorName( code ),
     163              :                         expl,
     164            3 :                         loc.file_name(),
     165            3 :                         loc.line(),
     166            6 :                         loc.function_name() );
     167              : }
     168              : 
     169              : template <>
     170            2 : std::string error_message<verbose::o>( [[maybe_unused]] const error_t &code,
     171              :                                        [[maybe_unused]] const std::source_location &loc )
     172              : {
     173            4 :     return "";
     174              : }
     175              : 
     176              : template <>
     177            3 : std::string error_message<verbose::v>( const error_t &code, const std::source_location &loc )
     178              : {
     179            3 :     return internal::mxlib_error_message<verbose::v>( code, loc );
     180              : }
     181              : 
     182              : template <>
     183           29 : std::string error_message<verbose::vv>( const error_t &code, const std::source_location &loc )
     184              : {
     185           29 :     return internal::mxlib_error_message<verbose::vv>( code, loc );
     186              : }
     187              : 
     188              : template <>
     189            3 : std::string error_message<verbose::vvv>( const error_t &code, const std::source_location &loc )
     190              : {
     191              :     return std::format( "An error has occurred:\n"
     192              :                         "    error: {} ({})\n"
     193              :                         "  in file: {}\n"
     194              :                         "  at line: {}\n"
     195              :                         "   source: {}\n",
     196            0 :                         errorMessage( code ),
     197            3 :                         errorName( code ),
     198            3 :                         loc.file_name(),
     199            3 :                         loc.line(),
     200            6 :                         loc.function_name() );
     201              : }
     202              : 
     203              : template <>
     204            2 : error_t error_report<verbose::o>( const error_t &code,
     205              :                                   [[maybe_unused]] const std::string &expl,
     206              :                                   [[maybe_unused]] const std::source_location &loc )
     207              : {
     208            2 :     return code;
     209              : }
     210              : 
     211              : template <>
     212            2 : error_t error_report<verbose::o>( const error_t &code, [[maybe_unused]] const std::source_location &loc )
     213              : {
     214            2 :     return code;
     215              : }
     216              : 
     217              : } // namespace mx
        

Generated by: LCOV version 2.0-1