Peach Exceptions - #1
Conversation
…erload for what()
| "ctestCommandArgs": "", | ||
| "inheritEnvironments": [ "clang_cl_x64_x64" ], | ||
| "variables": [] | ||
| "inheritEnvironments": [ "msvc_x64_x64" ] |
There was a problem hiding this comment.
Im pretty sure these files should be hidden?
There was a problem hiding this comment.
I would suggest to either remove this file from git or make is obvious that it is a IDE dependent file.
|
|
||
| namespace peach | ||
| { | ||
| enum class ExceptionTypes; |
There was a problem hiding this comment.
Since the ::detail part was removed in this file, this code can now be moved into the same scope as the rest
| std::forward< Tys >( args )... ) } | ||
|
|
||
| { | ||
| m_err_msg = this->what( ); |
There was a problem hiding this comment.
are we sure this is legal?
There was a problem hiding this comment.
Yes, this should be fine, as we do not overwrite what() and at this point the base std::runtime_error is fully constructed.
You should be able to omit the this->:
| m_err_msg = this->what( ); | |
| m_err_msg = what( ); |
| void print_to_console( ) const noexcept | ||
| { | ||
| // TODO: possibly determine if compiled application has a console available! | ||
| std::cerr << m_prefix << R"(( " )" << m_err_msg.substr( 0, m_err_msg.size( ) - 2 ) | ||
| << R"( " ))" << '\n'; | ||
| } |
There was a problem hiding this comment.
I would actually want to get rid of this, they can already get this precise message in a string, the user can just std::cout or print however the user seems fit, saves us a lot of trouble ensuring the constraints for this method
| ss << " }\n\n"; | ||
| const auto put_time = std::put_time( ¤t_time, "[%T]" ); | ||
|
|
||
| if ( line_num == constants::kNoSourceLocation && file_name.empty( ) ) |
There was a problem hiding this comment.
this is not the most elegant way, any alternatives?
There was a problem hiding this comment.
Isnt it enough to check for constants::kNoSourceLocation?
Also you could split the passing into the stringstream into multiple lines to avoid duplicate code in the if and else body.
There was a problem hiding this comment.
Its enough to check for constants::kNoSourceLocation but in case value of constants::kNoSourceLocation(-1) is passed but the file name isnt empty, then it should just assume it has the std::source_location data dont you recon?
The only time we dont want to use it is when we pass (constants::kNoSourceLocation, "") to format_error, any other case def isnt using that ctor - might as well be waterproof
There was a problem hiding this comment.
As for the duplicate code, theres no clean way to really do what you suggest - as both versions differ in quite some points somewhere in the middle of the stringstream. Do you have a suggestion on how to do it cleanly?
There was a problem hiding this comment.
something like this should work:
ss << '[' << prefix << ']' << put_time;
if ( line_num == constants::kNoSourceLocation && file_name.empty( ) )
{
ss << " -> { ";
} else
{
ss << '[' << prefix << ']' << put_time << " at (line:file) " << line_num << " : " << file_name
<< " ->\n\t\t{ ";
}
( ( ss << std::forward< Tys >( args ) << ' ' ), ... );
ss << " }\n\n";| .vs/ | ||
| out/ | ||
| /out | ||
| /build |
There was a problem hiding this comment.
Maybe reorder this to look nicer and remove the duplicate build folder
| "ctestCommandArgs": "", | ||
| "inheritEnvironments": [ "clang_cl_x64_x64" ], | ||
| "variables": [] | ||
| "inheritEnvironments": [ "msvc_x64_x64" ] |
There was a problem hiding this comment.
I would suggest to either remove this file from git or make is obvious that it is a IDE dependent file.
| } | ||
| // clang-format on | ||
|
|
||
| inline static std::string m_default_prefix = { "LOG" }; |
| // Short info: | ||
| // * Provides general way to set default prefix | ||
| // Link docu: | ||
| class PrefixManager |
There was a problem hiding this comment.
Creating instances of this does not really make any sense. So either the constructor should be protected (for inheritance to work), or we replace the class with a namespace that stores the default prefix (preferred by me).
| } | ||
| // clang-format on | ||
|
|
||
| std::string m_prefix; |
| // * The method what() isnt templated in the base class, so we cannot override what() | ||
| // * First ctor handles the case when std::source_location information is wanted, second does it without | ||
| // Link docu: | ||
| template< ExceptionTypes Val > class PeachException : virtual public detail::BaseException |
There was a problem hiding this comment.
I see no need to use virtual inheritance here.
| ss << " }\n\n"; | ||
| const auto put_time = std::put_time( ¤t_time, "[%T]" ); | ||
|
|
||
| if ( line_num == constants::kNoSourceLocation && file_name.empty( ) ) |
There was a problem hiding this comment.
Isnt it enough to check for constants::kNoSourceLocation?
Also you could split the passing into the stringstream into multiple lines to avoid duplicate code in the if and else body.
| const time_t t { std::time( nullptr ) }; | ||
| tm current_time { }; | ||
| localtime_s( ¤t_time, &t ); |
There was a problem hiding this comment.
IIRC localtime_s does not exist on Linux. So when ensuring Linux compatibility we will need to check for the platform we compile for. Therefore i would vote to create a function that returns the time in which we can do the platform dependent stuff .
| ss << " }\n\n"; | ||
| } | ||
|
|
||
| return std::string { ss.str( ) }; |
There was a problem hiding this comment.
Is the wrapping into the std::string really necessary? When the return type is std::string, it should be moved/copied anyway.
Overview
Changes:
Usage
Output
Note that paths here above are hidden with the three dots
Any changes on files besides the ones directly connected to your feature/change (emtpy if none):
Additional Notes:
Tests:
Extra