diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index e33a03bd6c5..91f3a586da6 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -280,7 +280,7 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, boo return result.str(); } -String icinga::DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose) +String icinga::DiagnosticInformation(const std::exception_ptr& eptr, bool verbose) { boost::stacktrace::stacktrace *pt = GetLastExceptionStack(); boost::stacktrace::stacktrace stack; @@ -295,12 +295,12 @@ String icinga::DiagnosticInformation(const boost::exception_ptr& eptr, bool verb context = *pc; try { - boost::rethrow_exception(eptr); + std::rethrow_exception(eptr); } catch (const std::exception& ex) { return DiagnosticInformation(ex, verbose, pt ? &stack : nullptr, pc ? &context : nullptr); + } catch (...) { + return boost::current_exception_diagnostic_information(); } - - return boost::diagnostic_information(eptr); } ScriptError::ScriptError(String message) diff --git a/lib/base/exception.hpp b/lib/base/exception.hpp index 178f4749364..b897fbbbda3 100644 --- a/lib/base/exception.hpp +++ b/lib/base/exception.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #ifdef _WIN32 @@ -115,7 +114,7 @@ std::string to_string(const ContextTraceErrorInfo& e); */ String DiagnosticInformation(const std::exception& ex, bool verbose = true, boost::stacktrace::stacktrace *stack = nullptr, ContextTrace *context = nullptr); -String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = true); +String DiagnosticInformation(const std::exception_ptr& eptr, bool verbose = true); class posix_error : virtual public std::exception, virtual public boost::exception { public: diff --git a/lib/base/workqueue.cpp b/lib/base/workqueue.cpp index a4793c0ae71..cdd2616c948 100644 --- a/lib/base/workqueue.cpp +++ b/lib/base/workqueue.cpp @@ -163,7 +163,7 @@ bool WorkQueue::HasExceptions() const * Returns all exceptions which have occurred for tasks in this work queue. When a * custom exception callback is set this method will always return an empty list. */ -std::vector WorkQueue::GetExceptions() const +std::vector WorkQueue::GetExceptions() const { std::unique_lock lock(m_Mutex); @@ -172,7 +172,7 @@ std::vector WorkQueue::GetExceptions() const void WorkQueue::ReportExceptions(const String& facility, bool verbose) const { - std::vector exceptions = GetExceptions(); + std::vector exceptions = GetExceptions(); for (const auto& eptr : exceptions) { Log(LogCritical, facility) @@ -236,7 +236,7 @@ void WorkQueue::RunTaskFunction(const TaskFunction& func) try { func(); } catch (const std::exception&) { - boost::exception_ptr eptr = boost::current_exception(); + std::exception_ptr eptr = std::current_exception(); { std::unique_lock mutex(m_Mutex); diff --git a/lib/base/workqueue.hpp b/lib/base/workqueue.hpp index fc37115555b..b69c86e6369 100644 --- a/lib/base/workqueue.hpp +++ b/lib/base/workqueue.hpp @@ -9,7 +9,6 @@ #include "base/ringbuffer.hpp" #include "base/logger.hpp" #include -#include #include #include #include @@ -52,7 +51,7 @@ bool operator<(const Task& a, const Task& b); class WorkQueue { public: - typedef std::function ExceptionCallback; + using ExceptionCallback = std::function; WorkQueue(size_t maxItems = 0, int threadCount = 1, LogSeverity statsLogLevel = LogInformation); ~WorkQueue(); @@ -113,7 +112,7 @@ class WorkQueue void SetExceptionCallback(const ExceptionCallback& callback); bool HasExceptions() const; - std::vector GetExceptions() const; + std::vector GetExceptions() const; void ReportExceptions(const String& facility, bool verbose = false) const; protected: @@ -137,7 +136,7 @@ class WorkQueue std::priority_queue > m_Tasks; int m_NextTaskID{0}; ExceptionCallback m_ExceptionCallback; - std::vector m_Exceptions; + std::vector m_Exceptions; Timer::Ptr m_StatusTimer; double m_StatusTimerTimeout; LogSeverity m_StatsLogLevel; diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 37a35d49916..03fc486dedd 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -438,7 +438,7 @@ int ConsoleCommand::RunScriptConsole(ScriptFrame& scriptFrame, const String& con result = ExecuteScript(l_Session, command, scriptFrame.Sandboxed); } catch (const ScriptError&) { /* Re-throw the exception for the outside try-catch block. */ - boost::rethrow_exception(boost::current_exception()); + throw; } catch (const std::exception& ex) { Log(LogCritical, "ConsoleCommand") << "HTTP query failed: " << ex.what(); diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 126c8de17fa..9407bb11207 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -89,7 +89,7 @@ void IdoMysqlConnection::Resume() SetConnected(false); - m_QueryQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_QueryQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); /* Immediately try to connect on Resume() without timer. */ m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityImmediate); @@ -130,7 +130,7 @@ void IdoMysqlConnection::Pause() } -void IdoMysqlConnection::ExceptionHandler(boost::exception_ptr exp) +void IdoMysqlConnection::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, "IdoMysqlConnection", "Exception during database operation: Verify that your database is operational!"); diff --git a/lib/db_ido_mysql/idomysqlconnection.hpp b/lib/db_ido_mysql/idomysqlconnection.hpp index c8462642786..6b41bbfce75 100644 --- a/lib/db_ido_mysql/idomysqlconnection.hpp +++ b/lib/db_ido_mysql/idomysqlconnection.hpp @@ -107,7 +107,7 @@ class IdoMysqlConnection final : public ObjectImpl void ClearTableBySession(const String& table); void ClearTablesBySession(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); void FinishConnect(double startTime); }; diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 845745e1a8c..9acdbab8412 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -97,7 +97,7 @@ void IdoPgsqlConnection::Resume() SetConnected(false); - m_QueryQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_QueryQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); /* Immediately try to connect on Resume() without timer. */ m_QueryQueue.Enqueue([this]() { Reconnect(); }, PriorityImmediate); @@ -129,7 +129,7 @@ void IdoPgsqlConnection::Pause() << "'" << GetName() << "' paused."; } -void IdoPgsqlConnection::ExceptionHandler(boost::exception_ptr exp) +void IdoPgsqlConnection::ExceptionHandler(std::exception_ptr exp) { Log(LogWarning, "IdoPgsqlConnection", "Exception during database operation: Verify that your database is operational!"); diff --git a/lib/db_ido_pgsql/idopgsqlconnection.hpp b/lib/db_ido_pgsql/idopgsqlconnection.hpp index f67d62b8768..02dcaf75df3 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.hpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.hpp @@ -91,7 +91,7 @@ class IdoPgsqlConnection final : public ObjectImpl void ClearTableBySession(const String& table); void ClearTablesBySession(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); void FinishConnect(double startTime); }; diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index c5dc084c0c8..df83a835042 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -369,9 +369,9 @@ void IcingaDB::UpdateAllConfigObjects() upqObjectType.Join(); if (upqObjectType.HasExceptions()) { - for (boost::exception_ptr exc : upqObjectType.GetExceptions()) { + for (std::exception_ptr exc : upqObjectType.GetExceptions()) { if (exc) { - boost::rethrow_exception(exc); + std::rethrow_exception(exc); } } } @@ -512,10 +512,10 @@ void IcingaDB::UpdateAllConfigObjects() upq.Join(); if (upq.HasExceptions()) { - for (boost::exception_ptr exc : upq.GetExceptions()) { + for (std::exception_ptr exc : upq.GetExceptions()) { try { if (exc) { - boost::rethrow_exception(exc); + std::rethrow_exception(exc); } } catch(const std::exception& e) { Log(LogCritical, "IcingaDB") diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index bc815918e7b..77869a8ab7e 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -76,7 +76,7 @@ void IcingaDB::Start(bool runtimeCreated) m_ConfigDumpInProgress = false; m_ConfigDumpDone = false; - m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_WorkQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); RedisConnInfo::ConstPtr connInfo = GetRedisConnInfo(); @@ -130,7 +130,7 @@ void IcingaDB::Start(bool runtimeCreated) m_PendingItemsThread = std::thread([this, keepAlive] { PendingItemsThreadProc(); }); } -void IcingaDB::ExceptionHandler(boost::exception_ptr exp) +void IcingaDB::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, "IcingaDB", "Exception during redis query. Verify that Redis is operational."); diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 647a00b674f..0cedd6730c3 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -414,7 +414,7 @@ class IcingaDB : public ObjectImpl void AssertOnWorkQueue(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); using SyncableTypeInfo = std::pair; static std::vector GetSyncableTypes(); diff --git a/lib/perfdata/elasticsearchwriter.cpp b/lib/perfdata/elasticsearchwriter.cpp index ce79b6939cd..34853ee2987 100644 --- a/lib/perfdata/elasticsearchwriter.cpp +++ b/lib/perfdata/elasticsearchwriter.cpp @@ -93,7 +93,7 @@ void ElasticsearchWriter::Resume() Log(LogInformation, "ElasticsearchWriter") << "'" << GetName() << "' resumed."; - m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_WorkQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); /* Setup timer for periodically flushing m_DataBuffer */ m_FlushTimer = Timer::Create(); @@ -576,7 +576,7 @@ void ElasticsearchWriter::AssertOnWorkQueue() ASSERT(m_WorkQueue.IsWorkerThread()); } -void ElasticsearchWriter::ExceptionHandler(boost::exception_ptr exp) +void ElasticsearchWriter::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, "ElasticsearchWriter", "Exception during Elastic operation: Verify that your backend is operational!"); diff --git a/lib/perfdata/elasticsearchwriter.hpp b/lib/perfdata/elasticsearchwriter.hpp index e9998d2bffb..64d5c684f08 100644 --- a/lib/perfdata/elasticsearchwriter.hpp +++ b/lib/perfdata/elasticsearchwriter.hpp @@ -54,7 +54,7 @@ class ElasticsearchWriter final : public ObjectImpl const Dictionary::Ptr& fields, double ts); void AssertOnWorkQueue(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); void FlushTimeout(); void Flush(); void SendRequest(const String& body); diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index 888d025c5b2..bd8f2315e8b 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -89,7 +89,7 @@ void GelfWriter::Resume() << "'" << GetName() << "' resumed."; /* Register exception handler for WQ tasks. */ - m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_WorkQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); m_Connection = new PerfdataWriterConnection{this, GetHost(), GetPort(), m_SslContext, !GetInsecureNoverify()}; m_LockedConnection.store(m_Connection); @@ -139,7 +139,7 @@ void GelfWriter::AssertOnWorkQueue() ASSERT(m_WorkQueue.IsWorkerThread()); } -void GelfWriter::ExceptionHandler(boost::exception_ptr exp) +void GelfWriter::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, "GelfWriter") << "Exception during Graylog Gelf operation: " << DiagnosticInformation(exp, false); Log(LogDebug, "GelfWriter") << "Exception during Graylog Gelf operation: " << DiagnosticInformation(exp, true); diff --git a/lib/perfdata/gelfwriter.hpp b/lib/perfdata/gelfwriter.hpp index 3663dfbe9de..8f06077ee4b 100644 --- a/lib/perfdata/gelfwriter.hpp +++ b/lib/perfdata/gelfwriter.hpp @@ -50,7 +50,7 @@ class GelfWriter final : public ObjectImpl void AssertOnWorkQueue(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); }; } diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 521b0fa0550..3d7c53b1d05 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -84,7 +84,7 @@ void GraphiteWriter::Resume() << "'" << GetName() << "' resumed."; /* Register exception handler for WQ tasks. */ - m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_WorkQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); m_Connection = new PerfdataWriterConnection{this, GetHost(), GetPort()}; m_LockedConnection.store(m_Connection); @@ -135,7 +135,7 @@ void GraphiteWriter::AssertOnWorkQueue() * * @param exp Exception pointer */ -void GraphiteWriter::ExceptionHandler(boost::exception_ptr exp) +void GraphiteWriter::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, "GraphiteWriter", "Exception during Graphite operation: Verify that your backend is operational!"); diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index 2785e5e29ca..aefdacb54f4 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -50,7 +50,7 @@ class GraphiteWriter final : public ObjectImpl void AssertOnWorkQueue(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); }; } diff --git a/lib/perfdata/influxdbcommonwriter.cpp b/lib/perfdata/influxdbcommonwriter.cpp index 1472c24e31b..d17f7208eab 100644 --- a/lib/perfdata/influxdbcommonwriter.cpp +++ b/lib/perfdata/influxdbcommonwriter.cpp @@ -83,7 +83,7 @@ void InfluxdbCommonWriter::Resume() << "'" << GetName() << "' resumed."; /* Register exception handler for WQ tasks. */ - m_WorkQueue.SetExceptionCallback([this](boost::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); + m_WorkQueue.SetExceptionCallback([this](std::exception_ptr exp) { ExceptionHandler(std::move(exp)); }); /* Setup timer for periodically flushing m_DataBuffer */ m_FlushTimer = Timer::Create(); @@ -135,7 +135,7 @@ void InfluxdbCommonWriter::AssertOnWorkQueue() ASSERT(m_WorkQueue.IsWorkerThread()); } -void InfluxdbCommonWriter::ExceptionHandler(boost::exception_ptr exp) +void InfluxdbCommonWriter::ExceptionHandler(std::exception_ptr exp) { Log(LogCritical, GetReflectionType()->GetName(), "Exception during InfluxDB operation: Verify that your backend is operational!"); diff --git a/lib/perfdata/influxdbcommonwriter.hpp b/lib/perfdata/influxdbcommonwriter.hpp index cfda0250133..4465ee7d40e 100644 --- a/lib/perfdata/influxdbcommonwriter.hpp +++ b/lib/perfdata/influxdbcommonwriter.hpp @@ -64,7 +64,7 @@ class InfluxdbCommonWriter : public ObjectImpl void AssertOnWorkQueue(); - void ExceptionHandler(boost::exception_ptr exp); + void ExceptionHandler(std::exception_ptr exp); }; template diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 7f2e91effdb..194e1cb5654 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -84,7 +84,7 @@ void OpenTsdbWriter::Resume() Log(LogInformation, "OpentsdbWriter") << "'" << GetName() << "' resumed."; - m_WorkQueue.SetExceptionCallback([](const boost::exception_ptr& exp) { + m_WorkQueue.SetExceptionCallback([](const std::exception_ptr& exp) { Log(LogDebug, "OpenTsdbWriter") << "Exception during OpenTsdb operation: " << DiagnosticInformation(exp); }); diff --git a/lib/perfdata/otlpmetricswriter.cpp b/lib/perfdata/otlpmetricswriter.cpp index 136cdc4f03a..5aa6707c65d 100644 --- a/lib/perfdata/otlpmetricswriter.cpp +++ b/lib/perfdata/otlpmetricswriter.cpp @@ -99,7 +99,7 @@ void OTLPMetricsWriter::Resume() Log(LogInformation, "OTLPMetricsWriter") << "'" << GetName() << "' resumed."; - m_WorkQueue.SetExceptionCallback([](boost::exception_ptr exp) { + m_WorkQueue.SetExceptionCallback([](std::exception_ptr exp) { Log(LogCritical, "OTLPMetricsWriter") << "Exception while producing OTel metric: " << DiagnosticInformation(exp); }); diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp index 40d6607f4b4..5e3cd1f813a 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -57,10 +57,8 @@ bool ActionsHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/configfileshandler.cpp b/lib/remote/configfileshandler.cpp index 7f33e067cf8..cd2d2eec300 100644 --- a/lib/remote/configfileshandler.cpp +++ b/lib/remote/configfileshandler.cpp @@ -81,12 +81,12 @@ bool ConfigFilesHandler::HandleRequest( response.result(http::status::ok); response.set(http::field::content_type, "application/octet-stream"); response.SendFile(path, yc); - } catch (const std::ios_base::failure& ex) { + } catch (const std::ios_base::failure&) { if (response.HasSerializationStarted()) { throw; } - HttpUtility::SendJsonError(response, params, 500, "Could not read file.", DiagnosticInformation(ex)); + HttpUtility::SendJsonError(response, params, 500, "Could not read file.", std::current_exception()); } return true; diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 943b21c1551..47a88a7a675 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -235,7 +235,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full Log(LogNotice, "ConfigObjectUtility") << "Failed to commit config item '" << fullName << "'. Aborting and removing config path '" << path << "'."; - for (const boost::exception_ptr& ex : upq.GetExceptions()) { + for (const std::exception_ptr& ex : upq.GetExceptions()) { errors->Add(DiagnosticInformation(ex, false)); if (diagnosticInformation) @@ -256,7 +256,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full Log(LogNotice, "ConfigObjectUtility") << "Failed to activate config object '" << fullName << "'. Aborting and removing config path '" << path << "'."; - for (const boost::exception_ptr& ex : upq.GetExceptions()) { + for (const std::exception_ptr& ex : upq.GetExceptions()) { errors->Add(DiagnosticInformation(ex, false)); if (diagnosticInformation) diff --git a/lib/remote/configpackageshandler.cpp b/lib/remote/configpackageshandler.cpp index 7e0dc976d1d..aa72326723a 100644 --- a/lib/remote/configpackageshandler.cpp +++ b/lib/remote/configpackageshandler.cpp @@ -54,9 +54,8 @@ void ConfigPackagesHandler::HandleGet(const HttpApiRequest& request, HttpApiResp try { packages = ConfigPackageUtility::GetPackages(); - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.", std::current_exception()); return; } @@ -120,9 +119,8 @@ void ConfigPackagesHandler::HandlePost(const HttpApiRequest& request, HttpApiRes std::unique_lock lock(ConfigPackageUtility::GetStaticPackageMutex()); ConfigPackageUtility::CreatePackage(packageName); - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.", std::current_exception()); return; } @@ -168,9 +166,8 @@ void ConfigPackagesHandler::HandleDelete(const HttpApiRequest& request, HttpApiR try { ConfigPackageUtility::DeletePackage(packageName); - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 500, "Failed to delete package '" + packageName + "'.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 500, "Failed to delete package '" + packageName + "'.", std::current_exception()); return; } diff --git a/lib/remote/configstageshandler.cpp b/lib/remote/configstageshandler.cpp index 8bcd16bbeb0..74d6fc61238 100644 --- a/lib/remote/configstageshandler.cpp +++ b/lib/remote/configstageshandler.cpp @@ -172,10 +172,9 @@ void ConfigStagesHandler::HandlePost(const HttpApiRequest& request, HttpApiRespo /* validate the config. on success, activate stage and reload */ ConfigPackageUtility::AsyncTryActivateStage(packageName, stageName, activate, reload, resetPackageUpdates); - } catch (const std::exception& ex) { - return HttpUtility::SendJsonError(response, params, 500, - "Stage creation failed.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 500, "Stage creation failed.", std::current_exception()); + return; } @@ -234,10 +233,11 @@ void ConfigStagesHandler::HandleDelete(const HttpApiRequest& request, HttpApiRes try { ConfigPackageUtility::DeleteStage(packageName, stageName); - } catch (const std::exception& ex) { - return HttpUtility::SendJsonError(response, params, 500, + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 500, "Failed to delete stage '" + stageName + "' in package '" + packageName + "'.", - DiagnosticInformation(ex)); + std::current_exception()); + return; } Dictionary::Ptr result1 = new Dictionary({ diff --git a/lib/remote/deleteobjecthandler.cpp b/lib/remote/deleteobjecthandler.cpp index beecc200152..e42a6755e7f 100644 --- a/lib/remote/deleteobjecthandler.cpp +++ b/lib/remote/deleteobjecthandler.cpp @@ -61,10 +61,8 @@ bool DeleteObjectHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index 07becaaf58c..36ec62e255c 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -430,7 +430,7 @@ void ProcessRequest( HttpHandler::ProcessRequest(waitGroup, request, response, yc); response.body().Finish(); - } catch (const std::exception& ex) { + } catch (const std::exception&) { /* Since we don't know the state the stream is in, we can't send an error response and * have to just cause a disconnect here. */ @@ -438,7 +438,7 @@ void ProcessRequest( throw; } - HttpUtility::SendJsonError(response, request.Params(), 500, "Unhandled exception", DiagnosticInformation(ex)); + HttpUtility::SendJsonError(response, request.Params(), 500, "Unhandled exception", std::current_exception()); } response.Flush(yc); diff --git a/lib/remote/httputility.cpp b/lib/remote/httputility.cpp index f868dae81f2..63b2d06958c 100644 --- a/lib/remote/httputility.cpp +++ b/lib/remote/httputility.cpp @@ -84,14 +84,14 @@ void HttpUtility::SendJsonBody(HttpApiResponse& response, const Dictionary::Ptr& } void HttpUtility::SendJsonError(HttpApiResponse& response, - const Dictionary::Ptr& params, int code, const String& info, const String& diagnosticInformation) + const Dictionary::Ptr& params, int code, const String& info, const std::exception_ptr& ex) { if (response.HasSerializationStarted()) { std::ostringstream err; err << "Impossible to send error response after streaming has started: error: '" << code << "', status: '" << info << "'"; - if (!diagnosticInformation.IsEmpty()) { - err << ", diagnostic_information: '" << diagnosticInformation << "'"; + if (ex) { + err << ", diagnostic_information: '" << DiagnosticInformation(ex) << "'"; } BOOST_THROW_EXCEPTION(std::logic_error{err.str()}); } @@ -102,8 +102,8 @@ void HttpUtility::SendJsonError(HttpApiResponse& response, result->Set("status", info); } - if (params && HttpUtility::GetLastParameter(params, "verbose") && !diagnosticInformation.IsEmpty()) { - result->Set("diagnostic_information", diagnosticInformation); + if (params && HttpUtility::GetLastParameter(params, "verbose") && ex) { + result->Set("diagnostic_information", DiagnosticInformation(ex)); } response.Clear(); diff --git a/lib/remote/httputility.hpp b/lib/remote/httputility.hpp index c8e5ccf2439..07464dac5cc 100644 --- a/lib/remote/httputility.hpp +++ b/lib/remote/httputility.hpp @@ -28,7 +28,7 @@ class HttpUtility static void SendJsonBody(HttpApiResponse& response, const Dictionary::Ptr& params, const Value& val, boost::asio::yield_context& yc); static void SendJsonBody(HttpApiResponse& response, const Dictionary::Ptr& params, const Value& val); static void SendJsonError(HttpApiResponse& response, const Dictionary::Ptr& params, const int code, - const String& info = {}, const String& diagnosticInformation = {}); + const String& info = {}, const std::exception_ptr& ex = nullptr); static bool IsValidHeaderName(std::string_view name); static bool IsValidHeaderValue(std::string_view value); diff --git a/lib/remote/modifyobjecthandler.cpp b/lib/remote/modifyobjecthandler.cpp index 3c0ae41ca88..1f8709304ee 100644 --- a/lib/remote/modifyobjecthandler.cpp +++ b/lib/remote/modifyobjecthandler.cpp @@ -59,10 +59,8 @@ bool ModifyObjectHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp index ef73515c40a..f33441d086a 100644 --- a/lib/remote/objectqueryhandler.cpp +++ b/lib/remote/objectqueryhandler.cpp @@ -181,10 +181,8 @@ bool ObjectQueryHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/statushandler.cpp b/lib/remote/statushandler.cpp index 4202b6a872a..e50d030b3f3 100644 --- a/lib/remote/statushandler.cpp +++ b/lib/remote/statushandler.cpp @@ -105,10 +105,8 @@ bool StatusHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/templatequeryhandler.cpp b/lib/remote/templatequeryhandler.cpp index 0684df68101..838fdede81d 100644 --- a/lib/remote/templatequeryhandler.cpp +++ b/lib/remote/templatequeryhandler.cpp @@ -122,10 +122,8 @@ bool TemplateQueryHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No templates found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No templates found.", std::current_exception()); return true; } diff --git a/lib/remote/typequeryhandler.cpp b/lib/remote/typequeryhandler.cpp index 9460070a2e6..e68ce0a0f97 100644 --- a/lib/remote/typequeryhandler.cpp +++ b/lib/remote/typequeryhandler.cpp @@ -84,10 +84,8 @@ bool TypeQueryHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No objects found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No objects found.", std::current_exception()); return true; } diff --git a/lib/remote/variablequeryhandler.cpp b/lib/remote/variablequeryhandler.cpp index c5634de3bb1..f2d3d66bb0a 100644 --- a/lib/remote/variablequeryhandler.cpp +++ b/lib/remote/variablequeryhandler.cpp @@ -94,10 +94,8 @@ bool VariableQueryHandler::HandleRequest( } catch (const MissingPermissionError& ex) { HttpUtility::SendJsonError(response, params, 403, ex.what()); return true; - } catch (const std::exception& ex) { - HttpUtility::SendJsonError(response, params, 404, - "No variables found.", - DiagnosticInformation(ex)); + } catch (const std::exception&) { + HttpUtility::SendJsonError(response, params, 404, "No variables found.", std::current_exception()); return true; }