-
Notifications
You must be signed in to change notification settings - Fork 98
refactor: Centralize error output #3902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
… 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.
…/catch in main)": remove useless try/catch
…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".
| 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(); |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/coreComponents/dataRepository/unitTests/testErrorHandling.cpp
Outdated
Show resolved
Hide resolved
| * @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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
| 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 ); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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() \ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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(); \ |
There was a problem hiding this comment.
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.
| ErrorContext{"", | ||
| { { ErrorContext::Attribute::Signal, | ||
| std::to_string( signal ) } }, | ||
| 1 }, |
There was a problem hiding this comment.
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())
Remove code duplication found in
GEOS_THROW,GEOS_ERROR,GEOS_WARNINGand put into a static function inErrorLogger.Called while
flushErrorMsg().Move all Exceptions under GeosExceptions.hpp