Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 29 additions & 10 deletions src/coreComponents/common/initializeEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ void setupLogger()

{ // setup error handling (using LvArray helper system functions)

///// set external error handling behaviour /////
ExternalErrorHandler::instance().enableStderrPipeDeviation( true );

///// set external error handling behaviour /////
ExternalErrorHandler::instance().setErrorHandling( []( string_view errorMsg,
string_view detectionLocation )
{
Expand Down Expand Up @@ -105,25 +105,44 @@ void setupLogger()
// 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
// first of all, there can be external error that await to be output
ExternalErrorHandler::instance().flush( "before signal error output" );

// error message output
std::string const stackHistory = LvArray::system::stackTrace( true );
DiagnosticMsg diagnosticMsg;
ErrorLogger::global().flushErrorMsg( DiagnosticMsgBuilder::init( diagnosticMsg,
MsgType::ExternalError, "",
::geos::logger::internal::g_rank )
.addSignal( signal )
.addCallStackInfo( stackHistory )
.getDiagnosticMsg() );
DiagnosticMsgBuilder::init( diagnosticMsg,
MsgType::ExternalError, "",
::geos::logger::internal::g_rank )
.addSignal( signal )
.addCallStackInfo( stackHistory );
ErrorLogger::global().flushErrorMsg( diagnosticMsg );

// call program termination
LvArray::system::callErrorHandler();
ErrorHandler::instance().abortProgram();
} );

///// set Post-Handled Error behaviour /////
///// set LvArray to use the GEOS error behaviour in a way that can be traced /////
LvArray::system::setErrorHandler( []()
{
// first of all, there can be external error that await to be output
ExternalErrorHandler::instance().flush( "after LvArray error detection" );

// default error message output
DiagnosticMsg diagnosticMsg;
DiagnosticMsgBuilder::init( diagnosticMsg,
MsgType::ExternalError,
"LvArray Runtime Error",
::geos::logger::internal::g_rank )
.addCallStackInfo( LvArray::system::stackTrace( true ) );
ErrorLogger::global().flushErrorMsg( diagnosticMsg );

// call program termination
ErrorHandler::instance().abortProgram();
} );

///// set Post-Handled Error behaviour /////
ErrorHandler::instance().setProgramAborter( []()
{
#if defined( GEOS_USE_MPI )
int mpi = 0;
Expand Down
10 changes: 10 additions & 0 deletions src/coreComponents/common/logger/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,14 @@ void ErrorLogger::flushCurrentExceptionMessage()
}
}

ErrorHandler::ErrorHandler()
: m_abortingFunctor( []() { std::abort(); } )
{}

ErrorHandler & ErrorHandler::instance()
{
static ErrorHandler s_instance;
return s_instance;
}

} /* namespace geos */
24 changes: 24 additions & 0 deletions src/coreComponents/common/logger/ErrorHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,31 @@ class ErrorLogger
std::string_view indent );
};

class ErrorHandler
{
public:

static ErrorHandler & instance();

void setProgramAborter( std::function< void() > const & abortingFunctor )
{ m_abortingFunctor = abortingFunctor; }

/**
* @brief Post error-handling function that terminates the program.
*/
void abortProgram()
{ m_abortingFunctor(); }

private:

std::function< void() > m_abortingFunctor;

/**
* @brief Static class, no public constructor
*/
ErrorHandler();

};

} /* namespace geos */

Expand Down
2 changes: 1 addition & 1 deletion src/coreComponents/common/logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
.addCallStackInfo( LvArray::system::stackTrace( true ) ) \
.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ )); \
GEOS_GLOBAL_LOGGER.flushCurrentExceptionMessage(); \
LvArray::system::callErrorHandler(); \
ErrorHandler::instance().abortProgram(); \
} \
}while( false )
#elif __CUDA_ARCH__
Expand Down
4 changes: 2 additions & 2 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main( int argc, char *argv[] )
{ // GEOS generated exceptions management
ErrorLogger::global().flushCurrentExceptionMessage();
basicCleanup( true );
LvArray::system::callErrorHandler();
ErrorHandler::instance().abortProgram();
}
catch( std::exception const & e )
{ // native exceptions management
Expand All @@ -91,7 +91,7 @@ int main( int argc, char *argv[] )
.addCallStackInfo( LvArray::system::stackTrace( true ) )
.getDiagnosticMsg());
basicCleanup( true );
LvArray::system::callErrorHandler();
ErrorHandler::instance().abortProgram();
}
return 0;
}
Loading