Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
c846586
creation of an object header that logs errors and warnings in a yaml …
amandinehry Apr 25, 2025
f1713fa
Set up ErrorHandling
amandinehry Apr 30, 2025
4e5250f
traits errors commented (to treat)
amandinehry Apr 30, 2025
94b775c
Set up test
amandinehry Apr 30, 2025
1cb8aa3
Modification to properly format the yaml so that it can be parsed if …
amandinehry Apr 30, 2025
9d5e16a
Test to add variadic arguments
amandinehry May 2, 2025
2f7660c
draft: retrieve data contexts info
amandinehry May 5, 2025
6036551
Added additional information in the yaml - not functional missing the…
amandinehry May 5, 2025
46b4904
First attempt at outputting exceptions
amandinehry May 7, 2025
e1aed93
Complete: code for outputting errors into yaml
amandinehry May 9, 2025
bc953be
Manage the text contained in the potential exception
amandinehry May 12, 2025
1a434bc
First attempt: Handling the text contained in the potential exception…
amandinehry May 14, 2025
acf4d99
Complete: yaml output for PVT tables error
amandinehry May 16, 2025
ee58884
YAML error message well formatted
amandinehry May 19, 2025
32a0237
Fix duplication error
amandinehry May 19, 2025
589270f
Add variadic parameters to GEOS_THROW_CTX_IF
amandinehry May 21, 2025
9b65581
Reorganization after operational tests
amandinehry May 21, 2025
b13f0a6
Apply the output error functionality in yaml to all geos errors
amandinehry May 21, 2025
6de2c6a
Latest update for exception handling (try/catch in main)
amandinehry May 27, 2025
5830aee
Add priority to the error message into the yaml file
amandinehry May 27, 2025
2b27c41
Update of the commit named "latest update for exception handling (try…
amandinehry May 27, 2025
86f793e
set priority
amandinehry May 27, 2025
8a8117e
errors cli modification: add --errors-output
amandinehry May 27, 2025
2c0f5aa
errors cli modification: add --errors-output
amandinehry May 27, 2025
eb2f691
Replace original macros
amandinehry May 27, 2025
7b5f293
Correction: replace original macros
amandinehry May 27, 2025
c07b502
Modification of the Optional function to accept arguments separated b…
amandinehry Jun 2, 2025
670ddfa
Reacting with the command line option -e / --errors-output
amandinehry Jun 2, 2025
d08a30f
Add the rank on which the error is catch for error and warning outputs
amandinehry Jun 3, 2025
5a6c1a0
Unit test to check if the contents of the yaml file match exactly wha…
amandinehry Jun 3, 2025
4928dcd
Add the "Exception" field into the message type enumeration
amandinehry Jun 4, 2025
02dcf50
Modify the macros corresponding to throw to allow the exception to be…
amandinehry Jun 4, 2025
59ac94d
Remove ASSERT dependency on LvArray
amandinehry Jun 4, 2025
835e444
Remove GEOS_THROW_(...) and GEOS_ERROR_(...) dependency on LvArray
amandinehry Jun 4, 2025
10a2627
Restore to its original state an input file that I used for my tests
amandinehry Jun 4, 2025
9bd9f30
Delete additionnal spaces
amandinehry Jun 4, 2025
c9fea30
Syntax fixes
amandinehry Jun 4, 2025
7fa2b74
Syntax fixes
amandinehry Jun 4, 2025
8a9ff29
xsd + revert comment
amandinehry Jun 4, 2025
c1e001e
xsd + check includes
amandinehry Jun 4, 2025
e31f17c
Merge remote-tracking branch 'upstream/develop' into feature/amandine…
amandinehry Jun 4, 2025
a0eefd2
Compilation error fix
amandinehry Jun 5, 2025
5caa099
Remove vscode config files
amandinehry Jun 5, 2025
7aee0c6
Remove empty comment lines and commented code
amandinehry Jun 10, 2025
80bb07b
Changes in macros names
amandinehry Jun 10, 2025
149789e
Change the loop syntax ito a for-each syntax to solve the issue of in…
amandinehry Jun 10, 2025
74de273
Add comments
amandinehry Jun 10, 2025
92e6854
Reorganization of declarations
amandinehry Jun 10, 2025
f910d0e
add g_ before global variables + add comment to the addToMsg() method
amandinehry Jun 10, 2025
67fce43
Fix in writing the stack trace in the yaml
amandinehry Jun 11, 2025
387687d
Merge remote-tracking branch 'origin/develop' into feature/amandinehr…
amandinehry Jun 11, 2025
5c801a5
Add an error msg when the call stack is not formatted as expected + r…
amandinehry Jun 11, 2025
e34c90d
Add comment in the write() function
amandinehry Jun 11, 2025
5c4fbcb
Modification of the streamMultilineYamlAttribute() function: no longe…
amandinehry Jun 11, 2025
75eff27
Modification of the streamMultilineYamlAttribute() method: take the i…
amandinehry Jun 11, 2025
dab2da5
Fix null pointer access on parent by using instance field instead
amandinehry Jun 11, 2025
0a95296
Add comments
amandinehry Jun 11, 2025
c4a002e
Just silently kill GEOS when a NotAnError is raised
amandinehry Jun 11, 2025
cbc5102
Removed the pointer to an Error Logger object (this is no longer usef…
amandinehry Jun 12, 2025
3318d85
Minor syntax modification
amandinehry Jun 12, 2025
343b830
Renaming ContextInfo in ErrorContext + minor correction on the format…
amandinehry Jun 12, 2025
e22e538
Minor modifications on the GEOS_THROW_IF_GT_MSG message
amandinehry Jun 12, 2025
8de9060
Using GEOS_LOG_RANK instead of GEOS_LOG
amandinehry Jun 12, 2025
6c762e7
Add an enumeration to secure the keys that can be entered for the map…
amandinehry Jun 12, 2025
d288490
Improved code comments
amandinehry Jun 13, 2025
99d9b5b
reverse the change from GEOS_LOG to GEOS_LOG_RANK +empty the object a…
amandinehry Jun 13, 2025
f929f97
minor changes syntax + remove isValidStackTrace() method and replace …
amandinehry Jun 13, 2025
709d8a4
Minor changes: string to string_view when it was possible + add an ad…
amandinehry Jun 16, 2025
051e85b
Remove try/catch in the createFile() and the flushCurrentErrorMsg() m…
amandinehry Jun 16, 2025
517782b
Renaming: flushCurrentErrorMsg() into flushErrorMsg()
amandinehry Jun 16, 2025
2e0e396
Change GEOS_LOG() to GEOS_LOG_RANK()
amandinehry Jun 18, 2025
a83a3a1
initialize the error message line by default
amandinehry Jun 19, 2025
9fe289a
Doxygen comments
amandinehry Jun 24, 2025
da7dc82
Comments added
amandinehry Jun 24, 2025
260133e
Sort contextual information by decreasing priority
amandinehry Jun 24, 2025
e0c876f
Simplification of the for loop which write context information
amandinehry Jun 24, 2025
e1a2128
Changes following comments received on my PR
amandinehry Jun 25, 2025
4811b6c
Unit test implemented
amandinehry Jun 25, 2025
4a8ea5b
evaluate MSG only one time in macros
amandinehry Jul 4, 2025
2b38577
Merge commit '7e85e747ec65cd498ba0e9e4730f79d2692ed0bd' into feature/…
MelReyCG Jul 8, 2025
127f38e
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' of …
amandinehry Jul 21, 2025
e9508f5
Merge remote-tracking branch 'upstream/develop' into feature/amandine…
amandinehry Jul 21, 2025
7fc0ced
🔊 warn the deveveloppers that a yamlFile should not be written if not…
MelReyCG Jul 21, 2025
35f7686
🐛 ⏪ set the --errorsOutput mandatory because of bug + revert optionpa…
MelReyCG Jul 23, 2025
31842a5
✏️ typo
MelReyCG Jul 25, 2025
a1105e4
🎨 uncrustify
MelReyCG Aug 1, 2025
c118dd4
🎨 docs alignement
MelReyCG Aug 1, 2025
4215fad
🎨 format
MelReyCG Aug 1, 2025
507ac66
builder pattern for addContextInfo
MelReyCG Aug 1, 2025
7b4ec52
♻️ refactor of the test: keeping only necessary testing, separated te…
MelReyCG Aug 1, 2025
a01d8ac
🐛 bugfix for test, wrong global instance impacting
MelReyCG Aug 1, 2025
d4c465b
🎨 format
MelReyCG Aug 1, 2025
1e32d65
Merge remote-tracking branch 'origin/develop' into feature/amandinehr…
MelReyCG Aug 1, 2025
6d10e3a
⏪ restored "Rank N:" if error messages
MelReyCG Aug 1, 2025
e9cd64c
test
amandinehry Aug 7, 2025
c7031bf
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' of …
amandinehry Aug 7, 2025
e07d0b7
uncomment the rmoveFile() function
amandinehry Aug 21, 2025
785636b
stack trace management
amandinehry Aug 21, 2025
dd3b844
Merge remote-tracking branch 'amandinehryFork/develop' into feature/a…
MelReyCG Aug 26, 2025
e0bad67
♻️ ✅ New GEOS_ERROR macros with context included + new unit macro uni…
MelReyCG Sep 15, 2025
ab40edc
✅ ♻️ Simplifying + testing macros (GEOS_ERROR_* and GEOS_ASSERT_*) + …
MelReyCG Sep 18, 2025
faa84fa
📝 adding macro docs
MelReyCG Sep 18, 2025
dd97f0e
✨ ✅ adding error cause in unit test
MelReyCG Sep 18, 2025
d708cac
♻️ reordered error & throw macro to group them
MelReyCG Sep 18, 2025
66ab5cb
♻️ ✅ uniformized warning macros
MelReyCG Sep 19, 2025
e6135b1
✅ 🐛 ⚡️ bugfix when callstack is empty + disable callstack for perfs
MelReyCG Sep 19, 2025
589fcfe
♻️ ✅ uniformized throw macros
MelReyCG Sep 19, 2025
6fc4b30
✅ removing _CTX macros from unit test
MelReyCG Sep 22, 2025
77f9fcb
🐛 use streamed cause string to support mpi pointers formatting (not s…
MelReyCG Sep 22, 2025
5747e7f
🐛 last mistake?
MelReyCG Sep 22, 2025
10eb969
♻️ removing all GEOS_*_CTX macros (as GEOS_ERROR, GEOS_WARNING, GEOS_…
MelReyCG Sep 22, 2025
2c5c5f5
🎨 UNCRUSTIFY
MelReyCG Sep 23, 2025
d1642e6
Merge remote-tracking branch 'origin/develop' into feature/amandinehr…
MelReyCG Sep 23, 2025
b3cbb99
Merge remote-tracking branch 'origin/develop' into feature/amandinehr…
MelReyCG Sep 23, 2025
5781a78
✨ allowing to re-throw with GEOS_THROW* macros
MelReyCG Sep 23, 2025
db75e45
📦 shema
MelReyCG Sep 23, 2025
e07ab72
♻️ removing unintended BASE::
MelReyCG Sep 23, 2025
754ed03
Merge remote-tracking branch 'origin/develop' into refactor/dudes/err…
arng40 Sep 24, 2025
83d0c0f
xsd
arng40 Sep 24, 2025
d5d8615
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
arng40 Sep 24, 2025
1913059
🎨 uncrustify
MelReyCG Sep 25, 2025
6692dd2
🐛 fix stream reset
MelReyCG Sep 25, 2025
29f6fbe
⚰️ unused variable
MelReyCG Sep 25, 2025
d17972f
✨ removing last LVARRAY_* error logging macros
MelReyCG Sep 25, 2025
759e9bb
Merge remote-tracking branch 'origin/develop' into feature/amandinehr…
MelReyCG Sep 25, 2025
1b755b5
✨ removing last LVARRAY_* error logging macros
MelReyCG Sep 25, 2025
3786db4
✅ adapting test with error cause addition
MelReyCG Sep 25, 2025
efa89d8
🐛 GPU Macros Support
MelReyCG Sep 25, 2025
7915205
🎨 uncrustify
MelReyCG Sep 26, 2025
14eefee
Merge branch 'develop' into feature/amandinehry/create-yaml-file-and-…
MelReyCG Sep 26, 2025
500bbfd
🐛 GPU forgotten instruction
MelReyCG Sep 26, 2025
fa8fa54
🐛 added pragmas to manual shadow global logger instance
MelReyCG Sep 26, 2025
a29510b
Merge branch 'feature/amandinehry/create-yaml-file-and-structure-2' o…
MelReyCG Sep 26, 2025
c501a0f
🐛 wrong conversion on GPU
MelReyCG Sep 29, 2025
a07810f
Merge branch 'develop' into feature/amandinehry/create-yaml-file-and-…
MelReyCG Sep 29, 2025
cbb5322
centralize error output
arng40 Sep 29, 2025
c743e15
remvove deplucated log
arng40 Sep 30, 2025
dc13b33
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
arng40 Sep 30, 2025
355e765
remove rank from arg
arng40 Oct 7, 2025
276606c
Merge remote-tracking branch 'origin/develop' into refactor/dudes/err…
arng40 Nov 5, 2025
3253a0b
fix after merge
arng40 Nov 5, 2025
cf0afc5
doc & fix
arng40 Nov 5, 2025
efcc52d
fix test
arng40 Nov 7, 2025
79b9791
test error
arng40 Nov 12, 2025
d951a16
initialize m_time
arng40 Nov 12, 2025
29dec26
add main for testUnits
arng40 Nov 12, 2025
6be688c
missing std::cout
arng40 Nov 13, 2025
62fa7ec
Merge remote-tracking branch 'origin/develop' into refactor/dudes/err…
arng40 Nov 13, 2025
5f9c74c
Merge remote-tracking branch 'origin/develop' into refactor/dudes/err…
arng40 Nov 20, 2025
95f631e
uncrust
arng40 Nov 21, 2025
df926d5
remove unecessary var
arng40 Nov 21, 2025
07b649a
doxygen
arng40 Nov 21, 2025
2fee6bf
clean
arng40 Nov 21, 2025
93594af
output only once
arng40 Nov 24, 2025
e430ae8
add "__" prefix
arng40 Nov 24, 2025
d5408c9
doxygen
arng40 Nov 24, 2025
17a394a
remove var duplication
arng40 Nov 24, 2025
061f502
fix format
arng40 Nov 24, 2025
450c3b0
add line number
arng40 Nov 24, 2025
d0ff49d
add stream to errorlogger + rename macro in logger
arng40 Nov 25, 2025
628e49c
reove debug log
arng40 Nov 25, 2025
f09d45f
fix test & cleanup
arng40 Nov 25, 2025
ec1feab
remove unecassery dep
arng40 Nov 25, 2025
419ba18
Merge branch 'develop' into refactor/dudes/error-context
arng40 Nov 26, 2025
9d5db85
fix test
arng40 Nov 27, 2025
2c9d6ce
Merge branch 'refactor/dudes/error-context' of https://github.com/GEO…
arng40 Nov 27, 2025
8708f2d
add geos::exception + refacto flushErrorMsg
arng40 Nov 28, 2025
3842caa
update exception inGEOS_THROW to geos::Exception
arng40 Nov 28, 2025
ae0b73c
update what() method
arng40 Nov 28, 2025
96bab37
remove unecessary cond
arng40 Dec 1, 2025
f47e62e
renaming and remove try catch from main
arng40 Dec 1, 2025
9289b82
add GeosExceptions
arng40 Dec 1, 2025
694e64e
clean up
arng40 Dec 1, 2025
b083853
remove unecessary include + some doc
arng40 Dec 1, 2025
b13149d
Merge remote-tracking branch 'origin/develop' into refactor/dudes/err…
arng40 Dec 1, 2025
e1b45f4
missong doc for GeosException
arng40 Dec 1, 2025
976aab5
include error
arng40 Dec 4, 2025
42c53b9
doxygen
arng40 Dec 4, 2025
16c9e77
update doxy
arng40 Dec 4, 2025
30baf23
remove include, + some clean
arng40 Dec 5, 2025
0aeddcf
fix cuda compil
arng40 Dec 8, 2025
ae60c25
move writeToAscii to cpp
arng40 Dec 8, 2025
5a52a75
doxygen
arng40 Dec 8, 2025
c48c52d
add log test
arng40 Dec 10, 2025
bbb72ff
fix log wrong formatting
arng40 Dec 10, 2025
855cf80
update log formatting & output
arng40 Dec 10, 2025
daec006
fix test
arng40 Dec 10, 2025
ab9895b
Uncrustify
arng40 Dec 10, 2025
60a1f3a
Merge branch 'develop' into refactor/dudes/error-context
arng40 Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreComponents/codingUtilities/Parsing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ char const * parseBuffer( char const * first,
* @param issep function that returns true if given character is a value separator
* @return @p last if the entire buffer has been processed, or pointer to
* the start of the unprocessed part if a parsing error occurred
* @throws std::runtime_error if file IO or parsing error occurred
* @throws geos::RuntimeError if file IO or parsing error occurred
*/
template< typename CONTAINER, typename SEPFUNC >
void parseFile( string const & filename,
Expand Down Expand Up @@ -134,13 +134,13 @@ void parseFile( string const & filename,
GEOS_THROW( GEOS_FMT( "Unable to parse value in file {} at position {}: {}...",
filename, static_cast< std::streamoff >( inputStream.tellg() ) - left,
string( ptr, std::min( left, std::ptrdiff_t{32} ) ) ),
std::runtime_error );
geos::RuntimeError );
}
}

GEOS_THROW_IF( inputStream.fail() && !inputStream.eof(),
GEOS_FMT( "Error while reading file {}: {}", filename, std::strerror( errno ) ),
std::runtime_error );
geos::RuntimeError );
}

} // namespace geos
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/codingUtilities/tests/testParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ParsingTest : public ::testing::TestWithParam< T >

geos::stdVector< T > vec;
auto const issep_invalid = []( char const c ){ return c == '|'; };
EXPECT_THROW( geos::parseFile( fname, vec, issep_invalid ), std::runtime_error );
EXPECT_THROW( geos::parseFile( fname, vec, issep_invalid ), geos::RuntimeError );

std::remove( fname.c_str() );
}
Expand Down
1 change: 1 addition & 0 deletions src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set( common_headers
GEOS_RAJA_Interface.hpp
GeosxMacros.hpp
MemoryInfos.hpp
logger/GeosExceptions.hpp
logger/Logger.hpp
logger/ErrorHandling.hpp
logger/ExternalErrorHandler.hpp
Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/common/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void makeDirectory( std::string const & path )
{
constexpr mode_t mode = 0770; // user and group rwx permissions
int const err = mkdir( path.c_str(), mode );
GEOS_THROW_IF( err && ( errno != EEXIST ), "Failed to create directory: " << path, std::runtime_error );
GEOS_THROW_IF( err && ( errno != EEXIST ), "Failed to create directory: " << path, geos::RuntimeError );
}

void makeDirsForPath( std::string const & path )
Expand Down
2 changes: 0 additions & 2 deletions src/coreComponents/common/format/table/TableLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
#ifndef GEOS_COMMON_FORMAT_TABLE_TABLELAYOUT_HPP
#define GEOS_COMMON_FORMAT_TABLE_TABLELAYOUT_HPP

#include "common/DataTypes.hpp"
#include "TableTypes.hpp"
#include <variant>
#include "common/logger/Logger.hpp"


namespace geos
Expand Down
2 changes: 2 additions & 0 deletions src/coreComponents/common/format/table/TableTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef GEOS_COMMON_FORMAT_TABLETYPES_HPP
#define GEOS_COMMON_FORMAT_TABLETYPES_HPP

#include "common/DataTypes.hpp"

namespace geos
{

Expand Down
50 changes: 18 additions & 32 deletions src/coreComponents/common/initializeEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,16 @@ void setupLogger()
{
std::string const stackHistory = LvArray::system::stackTrace( true );

GEOS_LOG( GEOS_FMT( "***** ERROR\n"
"***** LOCATION: (external error, detected {})\n"
"{}\n{}",
detectionLocation, errorMsg, stackHistory ) );
if( ErrorLogger::global().isOutputFileEnabled() )
{
ErrorLogger::ErrorMsg error;
error.setType( ErrorLogger::MsgType::Error );
error.addToMsg( errorMsg );
error.addRank( ::geos::logger::internal::g_rank );
error.addCallStackInfo( stackHistory );
error.addContextInfo(
ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( detectionLocation ) } } } );

ErrorLogger::global().flushErrorMsg( error );
}
ErrorLogger::ErrorMsg error;
error.setType( ErrorLogger::MsgType::Error );
error.addToMsg( errorMsg );
error.addRank( ::geos::logger::internal::g_rank );
error.addCallStackInfo( stackHistory );
error.addContextInfo(
ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( detectionLocation ) } },
string( detectionLocation ) } );

ErrorLogger::global().flushErrorMsg( error );

// we do not terminate the program as 1. the error could be non-fatal, 2. there may be more messages to output.
} );
Expand All @@ -124,26 +118,18 @@ void setupLogger()

// error message output
std::string const stackHistory = LvArray::system::stackTrace( true );

ErrorLogger::ErrorMsg error;
error.addSignalToMsg( signal );
error.setType( ErrorLogger::MsgType::Error );
error.addRank( ::geos::logger::internal::g_rank );
error.addCallStackInfo( stackHistory );
error.addContextInfo(
ErrorContext{ { { ErrorContext::Attribute::Signal, std::to_string( signal ) } }, "", 1 },
ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( "signal handler" ) } }, "", 0 } );

GEOS_LOG( GEOS_FMT( "***** ERROR\n"
"***** SIGNAL: {}\n"
"***** LOCATION: (external error, captured by signal handler)\n"
"{}\n{}",
signal, error.m_msg, stackHistory ) );
ErrorLogger::global().flushErrorMsg( error );

if( ErrorLogger::global().isOutputFileEnabled() )
{
error.setType( ErrorLogger::MsgType::Error );
error.addRank( ::geos::logger::internal::g_rank );
error.addCallStackInfo( stackHistory );
error.addContextInfo(
ErrorContext{ { { ErrorContext::Attribute::Signal, std::to_string( signal ) } }, 1 },
ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( "signal handler" ) } }, 0 } );

ErrorLogger::global().flushErrorMsg( error );
}

// call program termination
LvArray::system::callErrorHandler();
Expand Down
73 changes: 68 additions & 5 deletions src/coreComponents/common/logger/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,61 @@ static constexpr std::string_view g_level3Next = " ";

ErrorLogger g_errorLogger{};

/**
* @brief Retrieve all informations from the ErrorMsg and format and write into a stream.
* @param errMsg Class containing all the error/warning information
* @param oss The output stream to write the content to.
*/
void ErrorLogger::writeToAscii( ErrorLogger::ErrorMsg const & errMsg, std::ostream & oss )
{
/// HEADER
oss << "***** " << ErrorLogger::toString( errMsg.m_type ) << "\n";
if( !errMsg.m_signal.empty())
{
oss<< "***** SIGNAL: "<< errMsg.m_signal <<"\n";
}
oss << "***** LOCATION: " << errMsg.m_file<< " l." << errMsg.m_line << "\n";
oss << "***** " << errMsg.m_cause << "\n";
oss << "***** Rank " << stringutilities::join( errMsg.m_ranksInfo, ", " ) << "\n";

std::vector< ErrorLogger::ErrorContext > const contextsInfo = errMsg.m_contextsInfo;
/// ERROR CONTEXT
if( contextsInfo.empty())
{
oss << "***** Message :\n";
oss << errMsg.m_msg << "\n";
}
else
{
if( contextsInfo.size() >= 1 )
{

oss << "***** Message from " << contextsInfo.front().m_dataDisplayString<< ":\n";
oss << errMsg.m_msg << "\n";
}

if( contextsInfo.size() > 1 )
{
oss << "***** Additional contexts:\n";
for( size_t i = 1; i< contextsInfo.size(); i++ )
{
oss << "***** - " << contextsInfo[i].m_dataDisplayString << "\n";
}
}

}
///STACKTRACE
if( errMsg.m_sourceCallStack.size() > 0 )
{
oss << "\n** StackTrace of "<< errMsg.m_sourceCallStack.size() << " frames **\n";
for( size_t i = 0; i < errMsg.m_sourceCallStack.size(); i++ )
{
oss << GEOS_FMT( "Frame {}: {}\n", i, errMsg.m_sourceCallStack[i] );
}
oss << "=====\n";
}
}

ErrorLogger & ErrorLogger::global()
{ return g_errorLogger; }

Expand Down Expand Up @@ -228,10 +283,10 @@ void ErrorLogger::streamMultilineYamlAttribute( std::string_view msg, std::ofstr
}
}

void ErrorLogger::flushErrorMsg( ErrorLogger::ErrorMsg & errorMsg )
void ErrorLogger::writeToYaml( ErrorMsg & errorMsg )
{
std::ofstream yamlFile( std::string( m_filename ), std::ios::app );
if( yamlFile.is_open() && isOutputFileEnabled() )
if( yamlFile.is_open() )
{
// General errors info (type, rank on which the error occured)
yamlFile << g_level1Start << "type: " << ErrorLogger::toString( errorMsg.m_type ) << "\n";
Expand Down Expand Up @@ -291,12 +346,20 @@ void ErrorLogger::flushErrorMsg( ErrorLogger::ErrorMsg & errorMsg )
yamlFile << "\n";
yamlFile.flush();
errorMsg = ErrorMsg();
GEOS_LOG_RANK( GEOS_FMT( "The error file {} has been appended.\n", m_filename ) );
GEOS_LOG_RANK( GEOS_FMT( "The error file {} has been appended.", m_filename ) );
}
else
{
GEOS_LOG_RANK( GEOS_FMT( "Unable to open error file for writing.\n- Error file: {}\n- Error file enabled = {}.\n",
m_filename, isOutputFileEnabled() ) );
GEOS_LOG_RANK( GEOS_FMT( "Unable to open error file for writing.\n- Error file: {}\n", m_filename ) );
}
}

void ErrorLogger::flushErrorMsg( ErrorMsg & errorMsg )
{
writeToAscii( errorMsg, getErrorStream() );
if( isOutputFileEnabled() )
{
writeToYaml( errorMsg );
}
}

Expand Down
55 changes: 46 additions & 9 deletions src/coreComponents/common/logger/ErrorHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define INITIALIZATION_ERROR_LOGGER_HPP

#include "common/DataTypes.hpp"
#include "common/format/Format.hpp"
#include "common/format/StringUtilities.hpp"

namespace geos
{
Expand All @@ -33,13 +35,15 @@ class ErrorLogger
{

public:

/**
* @enum MsgType
* Enum listing the different types of possible errors
*/
enum class MsgType
{
Error,
ExternalError,
Warning,
Exception,
Undefined
Expand Down Expand Up @@ -75,6 +79,9 @@ class ErrorLogger
/// The key is a field of the Attribute enumeration and is converted to a string for writing in the YAML
map< Attribute, std::string > m_attributes;

/// String containing the target object name followed by the the file and line declaring it.
string m_dataDisplayString;

/**
* @brief Priority level assigned to an error context.
* @details Used to prioritize contextes (higher values = more relevant). Default is 0.
Expand Down Expand Up @@ -105,6 +112,8 @@ class ErrorLogger
{
/// the error type (Warning, Error or Exception)
MsgType m_type = ErrorLogger::MsgType::Undefined;
/// The signal received and formatted
std::string m_signal;
/// the error message that can be completed
std::string m_msg;
/// the cause of the error (erroneous condition, failed assertion...) if identified (optional)
Expand Down Expand Up @@ -230,6 +239,13 @@ class ErrorLogger
bool m_isValidStackTrace = false;
};

/**
* @brief Format all information in ErrorMsg and write it to the specified output stream
* @param errMsg The struct containing the error/warning object
* @param oss The output stream
*/
static void writeToAscii( ErrorLogger::ErrorMsg const & errMsg, std::ostream & oss );

/**
* @return Global instance of the ErrorLogger class used for error/warning reporting.
* @details This global instance is used across the codebase to log errors, warnings, and exceptions,
Expand All @@ -239,12 +255,6 @@ class ErrorLogger
*/
GEOS_HOST static ErrorLogger & global();

/**
* @return true if the YAML file output is enabled
*/
bool isOutputFileEnabled() const
{ return m_writeYaml; }

/**
* @brief Enable the YAML file output, which is false by default
* @param value A value of true enable the file writing
Expand All @@ -268,9 +278,8 @@ class ErrorLogger

/**
* @brief Gives acces to the error message that is currently being constructed,
* potencially at various application layers
* Use flushErrorMsg() when the message is fully constructed and you want it to be output
* @return Reference to the current instance for method chaining.
* potencially at various application layers (Typically for exceptions)
* @return Reference to the current error message instance;
*/
ErrorMsg & currentErrorMsg()
{ return m_currentErrorMsg; }
Expand All @@ -293,15 +302,43 @@ class ErrorLogger
* and reset the errorMsg instance to its initial state
* @param errorMsg a constant reference to the error
*/
void writeToYaml( ErrorMsg & errorMsg );

/**
* @brief Write all the information retrieved about the error/warning message into the output stream specified and
* optionnaly into a yaml file
* @param errorMsg a constant reference to the ErrorMsg
*/
void flushErrorMsg( ErrorMsg & errorMsg );

/**
* @return Return the const general log stream
*/
std::ostream const & getErrorStream() const
{ return m_stream; }

/**
* @return Return the reference general log stream
*/
std::ostream & getErrorStream()
{ return m_stream; }

private:
/// The error constructed via exceptions
ErrorMsg m_currentErrorMsg;
/// Indicate whether the write to YAML command line option is enabled
bool m_writeYaml = false;
/// YAML file name
std::string_view m_filename = "errors.yaml";
/// The stream used for the log output. By default used std::cout
std::ostream & m_stream = std::cout;


/**
* @return true if the YAML file output is enabled
*/
bool isOutputFileEnabled() const
{ return m_writeYaml; }

/**
* @brief Write the error message in the YAML file regarding indentation and line break
Expand Down
Loading
Loading