www.mooseframework.org
MooseError.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
14 #include "libmesh/string_to_enum.h"
15 
16 namespace moose
17 {
18 
19 namespace internal
20 {
21 
22 std::string
24 {
25  std::stringstream ss;
26  ss << libMesh::Utility::enum_to_string<FEFamily>(var1.feType().family) << ",ORDER"
27  << var1.feType().order
28  << " != " << libMesh::Utility::enum_to_string<FEFamily>(var2.feType().family) << ",ORDER"
29  << var2.feType().order;
30  return ss.str();
31 }
32 
33 std::string
34 mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color)
35 {
36  std::ostringstream oss;
37  oss << "\n" << color << "\n" << title << "\n" << msg << COLOR_DEFAULT << "\n";
38  return oss.str();
39 }
40 
41 std::string
42 mooseMsgFmt(const std::string & msg, const std::string & color)
43 {
44  std::ostringstream oss;
45  oss << "\n" << color << "\n" << msg << COLOR_DEFAULT << "\n";
46  return oss.str();
47 }
48 
49 [[noreturn]] void
50 mooseErrorRaw(std::string msg, const std::string prefix)
51 {
53  throw std::runtime_error(msg);
54 
55  msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED);
56 
57  std::ostringstream oss;
58  oss << msg << "\n";
59 
60  // this independent flush of the partial error message (i.e. without the
61  // trace) is here because trace retrieval can be slow in some
62  // circumstances, and we want to get the error message out ASAP.
63  msg = oss.str();
64  if (!prefix.empty())
65  MooseUtils::indentMessage(prefix, msg);
66  {
67  Threads::spin_mutex::scoped_lock lock(moose_stream_lock);
68  Moose::err << msg << std::flush;
69  }
70 
71  oss.str("");
73  print_trace(oss);
74 
75  msg = oss.str();
76  if (!prefix.empty())
77  MooseUtils::indentMessage(prefix, msg);
78 
79  {
80  Threads::spin_mutex::scoped_lock lock(moose_stream_lock);
81  Moose::err << msg << std::flush;
82 
85  }
86 
87  MOOSE_ABORT;
88 }
89 
90 void
91 mooseStreamAll(std::ostringstream &)
92 {
93 }
94 
95 } // namespace internal
96 
97 void
98 translateMetaPhysicLError(const MetaPhysicL::LogicError &)
99 {
100  mooseError(
101  "We caught a MetaPhysicL error in while performing element or face loops. This is "
102  "potentially due to AD not having a sufficiently large derivative container size. To "
103  "increase the AD container size, you can run configure in the MOOSE root directory with the "
104  "'--with-derivative-size=<n>' option and then recompile. Other causes of MetaPhysicL logic "
105  "errors include evaluating functions where they are not defined or differentiable like sqrt "
106  "(which gets called for vector norm functions) or log with arguments <= 0");
107 }
108 
109 } // 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:91
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:642
processor_id_type global_n_processors()
std::string incompatVarMsg(MooseVariableFieldBase &var1, MooseVariableFieldBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:23
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
void translateMetaPhysicLError(const MetaPhysicL::LogicError &)
emit a relatively clear error message when we catch a MetaPhysicL logic error
Definition: MooseError.C:98
This class provides an interface for common operations on field variables of both FE and FV types wit...
void write_traceout()
const FEType & feType() const
Get the type of finite element object.
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:721
Threads::spin_mutex moose_stream_lock
Definition: MooseError.h:134
void mooseErrorRaw(std::string msg, const std::string prefix="")
Definition: MooseError.C:50
void print_trace(std::ostream &out_stream=std::cerr)
bool _throw_on_error
Variable to turn on exceptions during mooseError(), should only be used within MOOSE unit tests or wh...
Definition: Moose.C:639
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:34