Skip to content
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

Log error in case consumer destructor throws #61

Merged
merged 1 commit into from
Apr 27, 2018

Conversation

accelerated
Copy link
Contributor

No description provided.

@@ -45,6 +45,8 @@

namespace cppkafka {

constexpr const char* library_name = "cppkafka";
Copy link
Owner

Choose a reason for hiding this comment

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

Can you just move this into Consumer::~Consumer? This is kind of out of place up here.

src/consumer.cpp Outdated
@@ -26,7 +26,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <syslog.h>
Copy link
Owner

Choose a reason for hiding this comment

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

This header doesn't exist on Windows. I'm not sure how rdkafka does this so it works on all platforms but this should do the same.

src/consumer.cpp Outdated
// If close throws just silently ignore until there's some
// logging facility (if any)
catch (const Exception& ex) {
auto& callback = get_configuration().get_log_callback();
Copy link
Owner

Choose a reason for hiding this comment

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

Can you make this const auto&? I prefer to explicitly indicate something is const instead of expecting the user to know that's the case.

src/consumer.cpp Outdated
catch (const Exception& ex) {
auto& callback = get_configuration().get_log_callback();
if (callback) {
callback(*this, LOG_ERR, library_name, ex.what());
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this should actually add some extra information here? I'm not sure the exception message would be enough for the user to realize what happened. Maybe something along the lines of "Failed to close consumer: <error-message>"?

@accelerated
Copy link
Contributor Author

Ok will address all these.

@accelerated accelerated force-pushed the consumer_destructor branch 4 times, most recently from 1b2ceb2 to dfba856 Compare April 25, 2018 15:25
@accelerated
Copy link
Contributor Author

i'll double check for windows compatibility next time...I keep forgetting :)

@accelerated accelerated force-pushed the consumer_destructor branch from dfba856 to d55edb2 Compare April 26, 2018 15:49
@@ -38,6 +38,18 @@

namespace cppkafka {

// Based on syslog.h levels
enum LogLevel {
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this belongs on a new cppkafka/logging.h file? Not sure what else would go there but I think it's slightly off in this exceptions.h. Also, I'd use enum class so this is better scoped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I didn't use the class as you are not using it anywhere else, but I agree it's a better approach. Unfortunately this means that convertion enum->int has to be cast now.

Copy link
Owner

Choose a reason for hiding this comment

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

Looks like it's being used on half on the cases. This could be cleaned up in some major version.

src/consumer.cpp Outdated
// logging facility (if any)
catch (const Exception& ex) {
constexpr const char* library_name = "cppkafka";
std::ostringstream error_msg;
Copy link
Owner

Choose a reason for hiding this comment

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

Minor: use using std::ostringstream after include directives and remove the std:: specifier here.

@accelerated accelerated force-pushed the consumer_destructor branch from d55edb2 to 0f996a7 Compare April 27, 2018 04:07
@mfontanini mfontanini merged commit ae74814 into mfontanini:master Apr 27, 2018
@accelerated accelerated deleted the consumer_destructor branch May 23, 2018 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants