Skip to content

Conversation

@arng40
Copy link
Contributor

@arng40 arng40 commented Nov 5, 2025

Remove code duplication found in GEOS_THROW, GEOS_ERROR, GEOS_WARNING and put into a static function in ErrorLogger.
Called while flushErrorMsg().
Move all Exceptions under GeosExceptions.hpp

… link between GEOS_THROW_CTX_IF and LVARRAY_THROW_IF_TEST( EXP, MSG, TYPE )
… in try/catch statements

Problem: Retrieves everything that was thrown, so not just the message.
…y spaces.

The previous condition checked whether an argument was present and whether the option was immediately followed by a value like -test"value", which excluded valid cases like -test "value" et -test     "value".
Comment on lines 132 to 140
ErrorLogger::global().beginLogger()
.addSignalToMsg( signal )
.setType( ErrorLogger::MsgType::Error )
.addRank( ::geos::logger::internal::g_rank )
.addCallStackInfo( stackHistory )
.addContextInfo(
ErrorContext{ { { ErrorContext::Attribute::Signal, std::to_string( signal ) } }, 1 },
ErrorContext{ { { ErrorContext::Attribute::DetectionLoc, string( "signal handler" ) } }, 0 } )
.flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a unit test for signals would be a good thing.

"***** - {}\n",
testErrorLogger.getCurrentExceptionMsg().m_file, line1,
testErrorLogger.getCurrentExceptionMsg().m_cause,
context.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you switch with the most important context here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have the same remaks

* @note - local instances are possible for more specialized logging.
* - currently not available on GPU, use GEOS_WARNING/ERROR/ASSERT macros for this usecase.
*/
GEOS_HOST static ErrorLogger & global();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point, but just use thread_local here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I was wondering, what about the thread_local instances initialization?

Comment on lines 327 to 335
void flushCurrentExceptionMessage();

/**
* @brief Write all the information retrieved about the diagnostic message into the instance
* outputs (stream specified + optional yaml file)
* @param errorMsg a reference to the ErrorMsg to output, and will be re-initialized
* @note Used for warnings and non-exception errors
*/
void flushErrorMsg( DiagnosticMsg & errMsg );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide a oss parameter (with a default to std::cout)?

Copy link
Contributor

@MelReyCG MelReyCG Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my advise seems wrong as std::ostream & m_stream = std::cout; exists.

Comment on lines 61 to 71
m_formattingOSS.str("");
m_formattingOSS.clear();

ErrorLogger::writeToAscii( msg, m_formattingOSS );
m_cachedWhat = m_formattingOSS.bad() ? "Exception formatting error!" : m_formattingOSS.str();
}

private:
/// Formatted exception message for what() method
string m_cachedWhat;
/// Error message logger for structured error reporting
DiagnosticMsg m_errorMsg;
inline static thread_local std::ostringstream m_formattingOSS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a cpp?

.addCallStackInfo( LvArray::system::stackTrace( true ) ) \
.addToMsg( __msgoss.str() ) \
.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ )).get(); \
DiagnosticMsg exceptionMsg = GEOS_GLOBAL_LOGGER.initCurrentExceptionMessage() \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't initCurrentExceptionMessage() need

                               std::string_view msgContent,
                               integer rank,
                               std::string_view msgFile,
                               integer msgLine

?

.addToMsg( e.what() )
.addRank( ::geos::logger::internal::g_rank )
DiagnosticMsg diagnosticMsg;
ErrorLogger::global().flushErrorMsg( DiagnosticMsgBuilder::init( diagnosticMsg,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not initCurrentExceptionMessage()?

.addToMsg( __msgoss.str() ) \
.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ )).get(); \
.addContextInfo( GEOS_DETAIL_REST_ARGS( __VA_ARGS__ )) \
.getDiagnosticMsg(); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of unnecessary getDiagnosticMsg() in all usages.

Comment on lines +137 to +140
ErrorContext{"",
{ { ErrorContext::Attribute::Signal,
std::to_string( signal ) } },
1 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do that automatically in addSignalToMsg(), what do you think? (it would then be named addSignal())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI type: cleanup / refactor Non-functional change (NFC)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants