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 : #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 26 4 : incompatVarMsg(MooseVariableFEBase & var1, MooseVariableFEBase & var2) 27 : { 28 4 : std::stringstream ss; 29 4 : ss << libMesh::Utility::enum_to_string<FEFamily>(var1.feType().family) << ",ORDER" 30 4 : << var1.feType().order 31 8 : << " != " << libMesh::Utility::enum_to_string<FEFamily>(var2.feType().family) << ",ORDER" 32 4 : << var2.feType().order; 33 8 : return ss.str(); 34 4 : } 35 : 36 : std::string 37 37430 : mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color) 38 : { 39 37430 : std::ostringstream oss; 40 37430 : oss << "\n" << color << "\n" << title << "\n" << msg << COLOR_DEFAULT << "\n"; 41 74860 : return oss.str(); 42 37430 : } 43 : 44 : std::string 45 0 : mooseMsgFmt(const std::string & msg, const std::string & color) 46 : { 47 0 : std::ostringstream oss; 48 0 : oss << "\n" << color << "\n" << msg << COLOR_DEFAULT << "\n"; 49 0 : return oss.str(); 50 0 : } 51 : 52 : [[noreturn]] void 53 4438 : mooseErrorRaw(std::string msg, const std::string prefix) 54 : { 55 4438 : if (Moose::_throw_on_error) 56 248 : throw std::runtime_error(msg); 57 : 58 4190 : msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED); 59 : 60 4190 : std::ostringstream oss; 61 4190 : oss << msg << "\n"; 62 : 63 : // this independent flush of the partial error message (i.e. without the 64 : // trace) is here because trace retrieval can be slow in some 65 : // circumstances, and we want to get the error message out ASAP. 66 4190 : msg = oss.str(); 67 4190 : if (!prefix.empty()) 68 20 : MooseUtils::indentMessage(prefix, msg); 69 : { 70 4190 : Threads::spin_mutex::scoped_lock lock(moose_stream_lock); 71 4190 : Moose::err << msg << std::flush; 72 4190 : } 73 : 74 4190 : oss.str(""); 75 4190 : if (Moose::show_trace && libMesh::global_n_processors() == 1) 76 2730 : print_trace(oss); 77 : 78 4190 : msg = oss.str(); 79 4190 : if (!prefix.empty()) 80 20 : MooseUtils::indentMessage(prefix, msg); 81 : 82 : { 83 4190 : Threads::spin_mutex::scoped_lock lock(moose_stream_lock); 84 4190 : Moose::err << msg << std::flush; 85 : 86 4190 : if (libMesh::global_n_processors() > 1) 87 0 : libMesh::write_traceout(); 88 4190 : } 89 : 90 4190 : MOOSE_ABORT; 91 0 : } 92 : 93 : void 94 37841 : mooseStreamAll(std::ostringstream &) 95 : { 96 37841 : } 97 : 98 : std::string 99 6 : formatMooseDocumentedError(const std::string & repo_name, 100 : const unsigned int issue_num, 101 : const std::string & msg) 102 : { 103 6 : const auto & repo_url = Registry::getRepositoryURL(repo_name); 104 6 : std::stringstream oss; 105 6 : oss << msg << "\n\nThis error is documented at " << repo_url << "/issues/" << issue_num << "."; 106 12 : return oss.str(); 107 6 : } 108 : 109 : } // namespace internal 110 : 111 : void 112 0 : translateMetaPhysicLError(const MetaPhysicL::LogicError &) 113 : { 114 0 : mooseError( 115 : "We caught a MetaPhysicL error in while performing element or face loops. This is " 116 : "potentially due to AD not having a sufficiently large derivative container size. To " 117 : "increase the AD container size, you can run configure in the MOOSE root directory with the " 118 : "'--with-derivative-size=<n>' option and then recompile. Other causes of MetaPhysicL logic " 119 : "errors include evaluating functions where they are not defined or differentiable like sqrt " 120 : "(which gets called for vector norm functions) or log with arguments <= 0"); 121 : } 122 : 123 : } // namespace moose