From 8e9f02edada1ad0e6326d6ccc8db51bc9194f737 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 22 May 2021 18:11:51 +0200 Subject: [PATCH] Better fatal error reporting --- .../impl/listenbrainz/ListensSynchronizer.cpp | 5 +++ .../impl/listenbrainz/SendQueue.cpp | 8 +++-- .../include/scrobbling/Exception.hpp | 32 +++++++++++++++++++ src/libs/utils/impl/IOContextRunner.cpp | 20 ++++++++++-- src/lms/main.cpp | 6 ++-- 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/libs/scrobbling/include/scrobbling/Exception.hpp diff --git a/src/libs/scrobbling/impl/listenbrainz/ListensSynchronizer.cpp b/src/libs/scrobbling/impl/listenbrainz/ListensSynchronizer.cpp index a6db9b37..1a59abcf 100644 --- a/src/libs/scrobbling/impl/listenbrainz/ListensSynchronizer.cpp +++ b/src/libs/scrobbling/impl/listenbrainz/ListensSynchronizer.cpp @@ -32,6 +32,7 @@ #include "database/Track.hpp" #include "database/TrackList.hpp" #include "database/User.hpp" +#include "scrobbling/Exception.hpp" #include "utils/IConfig.hpp" #include "utils/Logger.hpp" #include "utils/Service.hpp" @@ -321,6 +322,10 @@ namespace Scrobbling::ListenBrainz LOG(DEBUG) << "getListens aborted"; return; } + else if (ec) + { + throw Exception {"GetListens timer failure: " + std::string {ec.message()} }; + } startGetListens(); })); diff --git a/src/libs/scrobbling/impl/listenbrainz/SendQueue.cpp b/src/libs/scrobbling/impl/listenbrainz/SendQueue.cpp index 21255328..aa1cfde7 100644 --- a/src/libs/scrobbling/impl/listenbrainz/SendQueue.cpp +++ b/src/libs/scrobbling/impl/listenbrainz/SendQueue.cpp @@ -21,6 +21,7 @@ #include +#include "scrobbling/Exception.hpp" #include "utils/Logger.hpp" #include "utils/String.hpp" @@ -228,9 +229,10 @@ namespace Scrobbling::ListenBrainz LOG(DEBUG) << "SendQueue: throttle aborted"; return; } - - if (ec) - LOG(ERROR) << "async_wait failed:" << ec.message(); + else if (ec) + { + throw Exception {"Throttle timer failure: " + std::string {ec.message()} }; + } _state = State::Idle; sendNextQueuedRequest(); diff --git a/src/libs/scrobbling/include/scrobbling/Exception.hpp b/src/libs/scrobbling/include/scrobbling/Exception.hpp new file mode 100644 index 00000000..b60f7189 --- /dev/null +++ b/src/libs/scrobbling/include/scrobbling/Exception.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include "utils/Exception.hpp" + +namespace Scrobbling +{ + + class Exception : public LmsException + { + public: + using LmsException::LmsException; + }; +} diff --git a/src/libs/utils/impl/IOContextRunner.cpp b/src/libs/utils/impl/IOContextRunner.cpp index 888dd786..934b3b64 100644 --- a/src/libs/utils/impl/IOContextRunner.cpp +++ b/src/libs/utils/impl/IOContextRunner.cpp @@ -17,16 +17,32 @@ * along with LMS. If not, see . */ -#include "utils/Logger.hpp" #include "utils/IOContextRunner.hpp" +#include + +#include "utils/Logger.hpp" + IOContextRunner::IOContextRunner(boost::asio::io_service& ioService, std::size_t threadCount) : _ioService {ioService} , _work {ioService} { LMS_LOG(UTILS, INFO) << "Starting IO Context with " << threadCount << " threads..."; for (std::size_t i {}; i < threadCount; ++i) - _threads.emplace_back([&] { _ioService.run(); }); + { + _threads.emplace_back([&] + { + try + { + _ioService.run(); + } + catch (const std::exception& e) + { + LMS_LOG(UTILS, FATAL) << "Exception caught in IO context: " << e.what(); + std::abort(); + } + }); + } } void diff --git a/src/lms/main.cpp b/src/lms/main.cpp index 65d626d7..ae7b34e1 100644 --- a/src/lms/main.cpp +++ b/src/lms/main.cpp @@ -294,13 +294,15 @@ int main(int argc, char* argv[]) LMS_LOG(MAIN, INFO) << "Quitting..."; res = EXIT_SUCCESS; } - catch(Wt::WServer::Exception& e) + catch (const Wt::WServer::Exception& e) { + LMS_LOG(MAIN, FATAL) << "Caught WServer::Exception: " << e.what(); std::cerr << "Caught a WServer::Exception: " << e.what() << std::endl; res = EXIT_FAILURE; } - catch(std::exception& e) + catch (const std::exception& e) { + LMS_LOG(MAIN, FATAL) << "Caught std::exception: " << e.what(); std::cerr << "Caught std::exception: " << e.what() << std::endl; res = EXIT_FAILURE; }