- 
                Notifications
    You must be signed in to change notification settings 
- Fork 99
Update the KafkaException using modern practices #241
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: main
Are you sure you want to change the base?
Conversation
C++20 source_location
C++20 source_location
| @mimiflynn could you please review this? | 
        
          
                include/kafka/KafkaException.h
              
                Outdated
          
        
      | { | ||
| public: | ||
| KafkaException(const char* filename, std::size_t lineno, const Error& error) | ||
| KafkaException(const std::source_location location = std::source_location::current(), const Error& error) | 
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 std::source_locationis quit an elegant choice, but it's not supported until c++20. (the project has to be compatible with c++14/17)
- default parameter values must be specified starting from the rightmost parameter and moving leftwards
- if we're using std::source_locationas the default parameter, we could get rid of the macroKAFKA THROW_ERRORas well -- justthrow KafkaException(error)at where we need it.
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.
Thanks for the feedback!
As far as I know, source_location was originally provided in Boost before being adopted into C++20.
Since project already depends on Boost (e.g., for boost::optional), using boost::source_location will not introduce any new external dependencies.
I also plan to update the code so that exceptions can be thrown directly via KafkaException(error) and remove the KAFKA_THROW_ERROR macro in the process.
What do you think?
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.
Yes, we have to use some trick for the optional, -- https://github.com/morganstanley/modern-cpp-kafka/blob/main/include/kafka/Types.h#L19
It also make the dependencies messy, https://github.com/morganstanley/modern-cpp-kafka/blob/main/.github/workflows/kafka_api_ci_tests.yml#L307
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.
While the boost::source_location solution is certainly elegant, I'm wondering if introducing a new Boost dependency might be a concern for the project.
I'd like to make sure we aren't adding complexity where we're trying to remove it.
Signed-off-by: downfa11 <[email protected]>
Signed-off-by: downfa11 <[email protected]>
In the existing method,
filenameandlinenoare expressed as follows, but in C++20, you can use the source_location feature.It may not be very significant, but I believe it is meaningful as it aligns with modern C++ syntax for this project.
@alex-q-chen sorry. I'm still learning and made some mistakes