-
Notifications
You must be signed in to change notification settings - Fork 97
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".
| /// The signal received and formatted | ||
| std::string m_signal; |
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.
That little guy seems to never be initialized (addSignalToMsg()?)
Maybe you can just remove it and read the Attribute::Signal entry
src/main/main.cpp
Outdated
| } | ||
| catch( std::exception const & e ) | ||
| { // native exceptions management | ||
| ErrorLogger::ErrorMsg & errMsg = ErrorLogger::global().currentErrorMsg(); |
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 think it lacks a lot of information here: at this point, IIRC, GEOS_THOW() has never been called, so the same information must be provided to the error message.
Appart from that, this part is a lot better!
| oss << PREFIX<< "LOCATION: " << errMsg.m_file; | ||
| if( errMsg.m_line > 0 ) | ||
| { | ||
| oss << " l." << errMsg.m_line; |
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.
You changed the format here in a way that prevent us, developpers, to ctrl+click the file location for quick access.
The LOCATION macro is:
#define LOCATION __FILE__ ":" STRINGIZE( __LINE__ )
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, you put an if there but not in the YAML format.
| : | ||
| m_type( msgType ), | ||
| m_msg( msgContent ), | ||
| m_ranksInfo( {rank} ), | ||
| m_file( msgFile ), | ||
| m_line( msgLine ), | ||
| m_commit( false ) {} |
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.
-> cpp
| * @return Reference to the current instance for method chaining. | ||
| */ | ||
| ErrorMsg & addToMsg( std::exception const & e, bool toEnd = false ); | ||
| ErrorMsg & addToMsg( std::exception const & e, bool const toEnd = false ); |
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.
Those const added to boolean values are implementation details, not interface matter, it should remain in the cpp.
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.
same for MsgType and integer below
| bool isCommited() const | ||
| { return m_commit; } |
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.
About this "commit" concept:
- Why is it needed? What problem does it aim to solve? Is the "commited" state really needed?
ErrorMsgis a data structure with some helper methods for building it, I don't think it should have any state in it.- I see your new
ErrorMsgBuilderclass, with a lot of copied method, with some of them having silenciously no effect. Could the methods be better distributed?
I propose ErrorMsg being a POD, with no state, and ErrorMsgBuilder having all the building methods.
Also, I would not bind ErrorMsgBuilder to an ErrorLogger instance but to the ErrorMsg instance. This way you don't need this two ways dependancies anymore, which does not exist for good reasons (duplicating flush() & violating encapsulation).
| * 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) |
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.
"Typically for exceptions"
Are there other use-cases?
| ErrorMsgBuilder beginLogger() | ||
| { | ||
| return ErrorMsgBuilder( *this ); | ||
| } |
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 that you tried to remove the "current error message" read-write accessor for encapsulation & clarity purpose, but I'm not sure the solution is better than the original: beginLogger() can be called multiple time in an exception stack scenario. I think buildCurrentErrorMsg() would be better named.
We could name flushErrorMsg() to flushCurrentErrorMsg() to emphasis the fact that the subject is the same.
| rank: 0 | ||
| message: >- | ||
| Table input error. | ||
| Empty Group: Base Test Class (file.xml, l.23) | ||
| Empty Group | ||
| contexts: | ||
| - priority: 2 | ||
| inputFile: /path/to/file.xml |
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.
The main context information are lost (Base Test Class (file.xml, l.23)).
|
|
||
| private: | ||
| ///@copydoc ErrorLogger::m_errorContext | ||
| ErrorLogger & m_errorContext; |
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.
If you keep it:
| ErrorLogger & m_errorContext; | |
| ErrorLogger & m_errorLogger; |
If you change it:
| ErrorLogger & m_errorContext; | |
| ErrorMsg & m_errorMsg; |
| ErrorContext( map< Attribute, std::string > attributes, integer priority ): | ||
| m_dataDisplayString( "" ), | ||
| m_attributes( attributes ), | ||
| m_priority( priority ) {}; |
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.
m_dataDisplayString is allowed as empty? Isn't that the source of your issue in the unit test?
| 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.
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