LCOV - code coverage report
Current view: top level - include/base - MooseBaseErrorInterface.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 23 23 100.0 %
Date: 2025-07-17 01:28:37 Functions: 285 723 39.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include <sstream>
      13             : #include "ConsoleStreamInterface.h"
      14             : #include "MooseError.h"
      15             : #include "MooseBase.h"
      16             : 
      17             : /**
      18             :  * Interface that provides APIs to output errors/warnings/info messages
      19             :  */
      20             : class MooseBaseErrorInterface : public ConsoleStreamInterface
      21             : {
      22             : public:
      23             :   MooseBaseErrorInterface(const MooseBase & base);
      24             : 
      25             :   /**
      26             :    * Emits an error prefixed with object name and type.
      27             :    */
      28             :   template <typename... Args>
      29        1569 :   [[noreturn]] void mooseError(Args &&... args) const
      30             :   {
      31        1569 :     std::ostringstream oss;
      32        1569 :     moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
      33        1598 :     _moose_base.callMooseError(oss.str(), /* with_prefix = */ true);
      34          29 :   }
      35             : 
      36             :   /**
      37             :    * Emits an error without the prefixing included in mooseError().
      38             :    */
      39             :   template <typename... Args>
      40             :   [[noreturn]] void mooseErrorNonPrefixed(Args &&... args) const
      41             :   {
      42             :     std::ostringstream oss;
      43             :     moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
      44             :     _moose_base.callMooseError(oss.str(), /* with_prefix = */ false);
      45             :   }
      46             : 
      47             :   /**
      48             :    * Emits a documented error with object name and type.
      49             :    *
      50             :    * Documented errors are errors that have an issue associated with them.
      51             :    *
      52             :    * The repository name \p repo_name links a named repository to a URL
      53             :    * and should be registered at the application level with registerRepository().
      54             :    * See Moose.C for an example of the "moose" repository registration.
      55             :    *
      56             :    * @param repo_name The repository name where the issue resides
      57             :    * @param issue_num The number of the issue
      58             :    * @param args The error message to be combined
      59             :    */
      60             :   template <typename... Args>
      61           5 :   [[noreturn]] void mooseDocumentedError(const std::string & repo_name,
      62             :                                          const unsigned int issue_num,
      63             :                                          Args &&... args) const
      64             :   {
      65           5 :     std::ostringstream oss;
      66           5 :     moose::internal::mooseStreamAll(oss, std::forward<Args>(args)...);
      67           5 :     const auto msg = moose::internal::formatMooseDocumentedError(repo_name, issue_num, oss.str());
      68           6 :     _moose_base.callMooseError(msg, /* with_prefix = */ true);
      69           2 :   }
      70             : 
      71             :   /**
      72             :    * Emits a warning prefixed with object name and type.
      73             :    */
      74             :   template <typename... Args>
      75        2382 :   void mooseWarning(Args &&... args) const
      76             :   {
      77        6991 :     moose::internal::mooseWarningStream(
      78        4764 :         _console, _moose_base.errorPrefix("warning"), std::forward<Args>(args)...);
      79        2223 :   }
      80             : 
      81             :   /**
      82             :    * Emits a warning without the prefixing included in mooseWarning().
      83             :    */
      84             :   template <typename... Args>
      85             :   void mooseWarningNonPrefixed(Args &&... args) const
      86             :   {
      87             :     moose::internal::mooseWarningStream(_console, std::forward<Args>(args)...);
      88             :   }
      89             : 
      90             :   template <typename... Args>
      91        1328 :   void mooseDeprecated(Args &&... args) const
      92             :   {
      93        3984 :     moose::internal::mooseDeprecatedStream(
      94        2656 :         _console, false, true, _moose_base.errorPrefix("deprecation"), std::forward<Args>(args)...);
      95        1328 :   }
      96             : 
      97             :   template <typename... Args>
      98        6396 :   void mooseInfo(Args &&... args) const
      99             :   {
     100       19188 :     moose::internal::mooseInfoStream(
     101       12792 :         _console, _moose_base.errorPrefix("information"), std::forward<Args>(args)...);
     102        6396 :   }
     103             : 
     104             : private:
     105             :   /// The MooseBase class deriving from this interface
     106             :   const MooseBase & _moose_base;
     107             : };

Generated by: LCOV version 1.14