From 81d2d09ba938431ebc13bdcf2136f05ac2a2cab0 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Tue, 13 Feb 2018 22:01:16 +0100 Subject: [PATCH] fix(mpd): Clear mpd error after getting error info Before, polybar would crash, trying to throw a server error because mpd_connection_get_server_error asserts that the error is of type server error, but it isn't because it was cleared --- src/adapters/mpd.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/adapters/mpd.cpp b/src/adapters/mpd.cpp index c5516fd2..2c2c68f0 100644 --- a/src/adapters/mpd.cpp +++ b/src/adapters/mpd.cpp @@ -29,15 +29,26 @@ namespace mpd { void check_errors(mpd_connection* conn) { check_connection(conn); + + string err_msg; + switch (mpd_connection_get_error(conn)) { case MPD_ERROR_SUCCESS: return; case MPD_ERROR_SERVER: - mpd_connection_clear_error(conn); - throw server_error(mpd_connection_get_error_message(conn), mpd_connection_get_server_error(conn)); + { + err_msg = mpd_connection_get_error_message(conn); + enum mpd_server_error server_err = mpd_connection_get_server_error(conn); + mpd_connection_clear_error(conn); + throw server_error(err_msg, server_err); + } default: - mpd_connection_clear_error(conn); - throw client_error(mpd_connection_get_error_message(conn), mpd_connection_get_error(conn)); + { + err_msg = mpd_connection_get_error_message(conn); + enum mpd_error err = mpd_connection_get_error(conn); + mpd_connection_clear_error(conn); + throw client_error(err_msg, err); + } } }