https://mooseframework.inl.gov
MooseError.C
Go to the documentation of this file.
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 #include "MooseError.h"
11 #include "MooseUtils.h"
12 #include "MooseVariable.h"
13 #include "Registry.h"
14 
15 #include "libmesh/string_to_enum.h"
16 
17 using namespace libMesh;
18 
19 namespace moose
20 {
21 
22 namespace internal
23 {
24 
25 std::string
27 {
28  std::stringstream ss;
29  ss << libMesh::Utility::enum_to_string<FEFamily>(var1.feType().family) << ",ORDER"
30  << var1.feType().order
31  << " != " << libMesh::Utility::enum_to_string<FEFamily>(var2.feType().family) << ",ORDER"
32  << var2.feType().order;
33  return ss.str();
34 }
35 
36 std::string
37 mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color)
38 {
39  std::ostringstream oss;
40  oss << "\n" << color << "\n" << title << "\n" << msg << COLOR_DEFAULT << "\n";
41  return oss.str();
42 }
43 
44 std::string
45 mooseMsgFmt(const std::string & msg, const std::string & color)
46 {
47  std::ostringstream oss;
48  oss << "\n" << color << "\n" << msg << COLOR_DEFAULT << "\n";
49  return oss.str();
50 }
51 
52 [[noreturn]] void
53 mooseErrorRaw(std::string msg,
54  const std::string & prefix /* = "" */,
55  const hit::Node * node /* = nullptr */)
56 {
58  throw MooseRuntimeError(msg, node);
59 
60  // If we have a node available, add in the hit context (file location)
61  if (node)
62  msg = Moose::hitMessagePrefix(*node) + msg;
63 
64  msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED);
65 
66  std::ostringstream oss;
67  oss << msg << "\n";
68 
69  // this independent flush of the partial error message (i.e. without the
70  // trace) is here because trace retrieval can be slow in some
71  // circumstances, and we want to get the error message out ASAP.
72  msg = oss.str();
73  if (!prefix.empty())
74  MooseUtils::indentMessage(prefix, msg);
75  {
76  Threads::spin_mutex::scoped_lock lock(moose_stream_lock);
77  Moose::err << msg << std::flush;
78  }
79 
80  oss.str("");
82  print_trace(oss);
83 
84  msg = oss.str();
85  if (!prefix.empty())
86  MooseUtils::indentMessage(prefix, msg);
87 
88  {
89  Threads::spin_mutex::scoped_lock lock(moose_stream_lock);
90  Moose::err << msg << std::flush;
91 
94  }
95 
96  MOOSE_ABORT;
97 }
98 
99 void
100 mooseStreamAll(std::ostringstream &)
101 {
102 }
103 
104 std::string
105 formatMooseDocumentedError(const std::string & repo_name,
106  const unsigned int issue_num,
107  const std::string & msg)
108 {
109  const auto & repo_url = Registry::getRepositoryURL(repo_name);
110  std::stringstream oss;
111  oss << msg << "\n\nThis error is documented at " << repo_url << "/issues/" << issue_num << ".";
112  return oss.str();
113 }
114 
115 } // namespace internal
116 
117 void
118 translateMetaPhysicLError(const MetaPhysicL::LogicError &)
119 {
120  mooseError(
121  "We caught a MetaPhysicL error in while performing element or face loops. This is "
122  "potentially due to AD not having a sufficiently large derivative container size. To "
123  "increase the AD container size, you can run configure in the MOOSE root directory with the "
124  "'--with-derivative-size=<n>' option and then recompile. Other causes of MetaPhysicL logic "
125  "errors include evaluating functions where they are not defined or differentiable like sqrt "
126  "(which gets called for vector norm functions) or log with arguments <= 0");
127 }
128 
129 } // namespace moose
void mooseStreamAll(std::ostringstream &ss)
All of the following are not meant to be called directly - they are called by the normal macros (moos...
Definition: MooseError.C:100
bool show_trace
Set to true (the default) to print the stack trace with error and warning messages - false to omit it...
Definition: Moose.C:783
const libMesh::FEType & feType() const
Get the type of finite element object.
processor_id_type global_n_processors()
std::string incompatVarMsg(MooseVariableFieldBase &var1, MooseVariableFieldBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:26
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:118
OrderWrapper order
This class provides an interface for common operations on field variables of both FE and FV types wit...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void write_traceout()
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN, bool dont_indent_first_line=true, const std::string &post_prefix=": ")
Indents the supplied message given the prefix and color.
Definition: MooseUtils.C:734
void print_trace(std::ostream &out_stream=std::cerr)
void mooseErrorRaw(std::string msg, const std::string &prefix="", const hit::Node *node=nullptr)
Main callback for emitting a moose error.
Definition: MooseError.C:53
static const std::string & getRepositoryURL(const std::string &repo_name)
Returns the repository URL associated with repo_name.
Definition: Registry.C:173
std::string hitMessagePrefix(const hit::Node &node)
Get the prefix to be associated with a hit node for a message.
Definition: Moose.C:767
Exception to be thrown whenever we have _throw_on_error set and a mooseError() is emitted...
Definition: MooseError.h:143
libMesh::Threads::spin_mutex moose_stream_lock
Definition: MooseError.h:166
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
Definition: Moose.C:780
std::string mooseMsgFmt(const std::string &msg, const std::string &title, const std::string &color)
Format a message for output with a title.
Definition: MooseError.C:37
std::string formatMooseDocumentedError(const std::string &repo_name, const unsigned int issue_num, const std::string &msg)
Formats a documented error.
Definition: MooseError.C:105