Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cee846a
✨ manage exit signals in GEOS, as errors + signal log messages no lon…
MelReyCG Jul 7, 2025
6c24825
💄 ajusting line break for consistency
MelReyCG Jul 7, 2025
9e46565
💄 add an option to reorder error msg parts, useful for signal msgs.
MelReyCG Jul 7, 2025
098c478
✨ capture external errors from stderr pipe in GEOS
MelReyCG Jul 7, 2025
7b1b383
✨ ♻️ adding detection location context information for signals & exte…
MelReyCG Jul 7, 2025
25c2418
💄 removing empty entries output from YAML
MelReyCG Jul 7, 2025
2ed4144
💄 adding detectionLocation YAML key
MelReyCG Jul 7, 2025
bdc07b2
💄 adding signal error metadata
MelReyCG Jul 7, 2025
531e3e3
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' int…
MelReyCG Jul 8, 2025
8077f10
sync with last feature/amandinehry/create-yaml-file-and-structure cha…
MelReyCG Jul 8, 2025
b001c07
Merge remote-tracking branch 'amandinehryFork/feature/amandinehry/cre…
MelReyCG Jul 21, 2025
01c4fcf
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' int…
MelReyCG Jul 21, 2025
ef37b51
🐛 do not try to output if not required
MelReyCG Jul 25, 2025
d1d998f
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' int…
MelReyCG Jul 25, 2025
751f785
Merge branch 'feature/amandinehry/create-yaml-file-and-structure' int…
MelReyCG Aug 26, 2025
9e42689
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
MelReyCG Sep 26, 2025
21d17a2
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
MelReyCG Oct 8, 2025
d9127d1
Merge remote-tracking branch 'amandinehryFork/feature/rey/signal-and-…
MelReyCG Oct 8, 2025
c4f4661
🐛 take into account new logger interface
MelReyCG Oct 8, 2025
6892fbe
Merge branch 'feature/amandinehry/create-yaml-file-and-structure-2' i…
MelReyCG Oct 10, 2025
f8fbc2c
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
MelReyCG Oct 13, 2025
d0b2314
Merge remote-tracking branch 'origin/feature/amandinehry/create-yaml-…
MelReyCG Oct 16, 2025
a115c05
🐛 applying base PR modif
MelReyCG Oct 20, 2025
0ea06d9
Merge branch 'feature/amandinehry/create-yaml-file-and-structure-2' i…
MelReyCG Oct 21, 2025
c55dabb
Merge branch 'feature/amandinehry/create-yaml-file-and-structure-2' i…
MelReyCG Oct 22, 2025
865b3dd
📝 missing docs
MelReyCG Oct 22, 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
3 changes: 2 additions & 1 deletion src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ set( common_headers
format/LogPart.hpp
format/Format.hpp
format/StringUtilities.hpp
logger/Logger.hpp
BufferAllocator.hpp
DataLayouts.hpp
DataTypes.hpp
Expand All @@ -41,6 +40,7 @@ set( common_headers
MemoryInfos.hpp
logger/Logger.hpp
logger/ErrorHandling.hpp
logger/ExternalErrorHandler.hpp
MpiWrapper.hpp
Path.hpp
Span.hpp
Expand Down Expand Up @@ -77,6 +77,7 @@ set( common_sources
format/StringUtilities.cpp
logger/Logger.cpp
logger/ErrorHandling.cpp
logger/ExternalErrorHandler.cpp
BufferAllocator.cpp
MemoryInfos.cpp
MpiWrapper.cpp
Expand Down
99 changes: 84 additions & 15 deletions src/coreComponents/common/initializeEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "LvArray/src/system.hpp"
#include "common/LifoStorageCommon.hpp"
#include "common/MemoryInfos.hpp"
#include "logger/ErrorHandling.hpp"
#include "logger/ExternalErrorHandler.hpp"
#include <umpire/TypedAllocator.hpp>
// TPL includes
#include <umpire/ResourceManager.hpp>
Expand Down Expand Up @@ -66,6 +68,88 @@ void setupLogger()
#else
logger::InitializeLogger();
#endif

{ // setup error handling (using LvArray helper system functions)
using ErrorContext = ErrorLogger::ErrorContext;

///// set Post-Handled Error behaviour /////
LvArray::system::setErrorHandler( []()
{
#if defined( GEOS_USE_MPI )
int mpi = 0;
MPI_Initialized( &mpi );
if( mpi )
{
MPI_Abort( MPI_COMM_WORLD, EXIT_FAILURE );
}
#endif
std::abort();
} );

///// set external error handling behaviour /////
ExternalErrorHandler::instance().setErrorHandling( []( string_view errorMsg,
string_view detectionLocation )
{
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 );
}

// we do not terminate the program as 1. the error could be non-fatal, 2. there may be more messages to output.
} );
ExternalErrorHandler::instance().enableStderrPipe( true );

///// set signal handling behaviour /////
LvArray::system::setSignalHandling( []( int const signal )
{
// Disable signal handling to prevent catching exit signal (infinite loop)
LvArray::system::setSignalHandling( nullptr );

// first of all, external error can await to be output, we must output them
ExternalErrorHandler::instance().flush( "before signal error output" );

// error message output
std::string const stackHistory = LvArray::system::stackTrace( true );
ErrorLogger::ErrorMsg error;
error.addSignalToMsg( signal );

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

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 All @@ -77,21 +161,6 @@ void finalizeLogger()
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setupLvArray()
{
LvArray::system::setErrorHandler( []()
{
#if defined( GEOS_USE_MPI )
int mpi = 0;
MPI_Initialized( &mpi );
if( mpi )
{
MPI_Abort( MPI_COMM_WORLD, EXIT_FAILURE );
}
#endif
std::abort();
} );

LvArray::system::setSignalHandling( []( int const signal ) { LvArray::system::stackTraceHandler( signal, true ); } );

#if defined(GEOS_USE_FPE)
LvArray::system::setFPE();
#else
Expand Down
54 changes: 48 additions & 6 deletions src/coreComponents/common/logger/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include <regex>
#include <string_view>

// signal management
#include <csignal>
#include <cfenv>
#include <cstring>

namespace geos
{
static constexpr std::string_view g_level1Start = " - ";
Expand Down Expand Up @@ -68,7 +73,9 @@ std::string ErrorLogger::ErrorContext::attributeToString( ErrorLogger::ErrorCont
case ErrorLogger::ErrorContext::Attribute::InputFile: return "inputFile";
case ErrorLogger::ErrorContext::Attribute::InputLine: return "inputLine";
case ErrorLogger::ErrorContext::Attribute::DataPath: return "dataPath";
default: return "Unknown";
case ErrorLogger::ErrorContext::Attribute::DetectionLoc: return "detectionLocation";
case ErrorLogger::ErrorContext::Attribute::Signal: return "signal";
default: return "unknown";
}
}

Expand Down Expand Up @@ -98,6 +105,39 @@ ErrorLogger::ErrorMsg & ErrorLogger::ErrorMsg::addToMsg( std::string_view errorM
return *this;
}

ErrorLogger::ErrorMsg & ErrorLogger::ErrorMsg::addSignalToMsg( int sig, bool toEnd )
{
if( sig == SIGFPE )
{
std::string errorMsg = "Floating point error encountered: \n";

if( std::fetestexcept( FE_DIVBYZERO ) )
errorMsg += "- Division by zero operation.\n";

if( std::fetestexcept( FE_INEXACT ) )
errorMsg += "- Inexact result.\n";

if( std::fetestexcept( FE_INVALID ) )
errorMsg += "- Domain error occurred in an earlier floating-point operation.\n";

if( std::fetestexcept( FE_OVERFLOW ) )
errorMsg += "- The result of the earlier floating-point operation was too large to be representable.\n";

if( std::fetestexcept( FE_UNDERFLOW ) )
errorMsg += "- The result of the earlier floating-point operation was subnormal with a loss of precision.\n";

return addToMsg( errorMsg,
toEnd );
}
else
{
// standard messages
return addToMsg( GEOS_FMT( "Signal no. {} encountered: {}\n",
sig, ::strsignal( sig ) ),
toEnd );
}
}

ErrorLogger::ErrorMsg & ErrorLogger::ErrorMsg::setCodeLocation( std::string_view msgFile, integer msgLine )
{
m_file = msgFile;
Expand Down Expand Up @@ -230,10 +270,12 @@ void ErrorLogger::flushErrorMsg( ErrorLogger::ErrorMsg & errorMsg )
}

// Location of the error in the code
yamlFile << g_level1Next << "sourceLocation:\n";
yamlFile << g_level2Next << "file: " << errorMsg.m_file << "\n";
yamlFile << g_level2Next << "line: " << errorMsg.m_line << "\n";

if( !errorMsg.m_file.empty() )
{
yamlFile << g_level1Next << "sourceLocation:\n";
yamlFile << g_level2Next << "file: " << errorMsg.m_file << "\n";
yamlFile << g_level2Next << "line: " << errorMsg.m_line << "\n";
}
// Information about the stack trace
if( !errorMsg.m_sourceCallStack.empty() )
{
Expand All @@ -249,7 +291,7 @@ void ErrorLogger::flushErrorMsg( ErrorLogger::ErrorMsg & errorMsg )
yamlFile << "\n";
yamlFile.flush();
errorMsg = ErrorMsg();
GEOS_LOG_RANK( GEOS_FMT( "The error file {} was appended.", m_filename ) );
GEOS_LOG_RANK( GEOS_FMT( "The error file {} has been appended.\n", m_filename ) );
}
else
{
Expand Down
14 changes: 13 additions & 1 deletion src/coreComponents/common/logger/ErrorHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class ErrorLogger
{
InputFile,
InputLine,
DataPath
DataPath,
DetectionLoc,
Signal,
};

/// The map contains contextual information about the error
Expand Down Expand Up @@ -157,6 +159,16 @@ class ErrorLogger
*/
ErrorMsg & addToMsg( std::string_view msg, bool toEnd = false );

/**
* @brief Add text to the error msg that occured according to the specified signal.
* - the signal can be one of the main error signals.
* - if the signal is SIGFPE, the nature of floating point error will be interpreted.
* @param signal The signal, from ISO C99 or POSIX standard.
* @param toEnd adds the message to the end if true, at the start otherwise.
* @return The instance, for builder pattern.
*/
ErrorMsg & addSignalToMsg( int signal, bool toEnd = false );

/**
* @brief Set the source code location values (file and line where the error is detected)
* @param msgFile Name of the source file location to add
Expand Down
Loading
Loading