Compare commits

...

1 Commits

Author SHA1 Message Date
albexk 60975c9596 Add method to log nested exceptions 2024-09-10 00:24:05 +03:00
3 changed files with 24 additions and 0 deletions
@@ -12,6 +12,7 @@
#include "configurators/wireguard_configurator.h" #include "configurators/wireguard_configurator.h"
#include "core/enums/apiEnums.h" #include "core/enums/apiEnums.h"
#include "version.h" #include "version.h"
#include "utilities.h"
namespace namespace
{ {
@@ -362,6 +363,7 @@ ErrorCode ApiController::getConfigForService(const QString &installationUuid, co
publicKey = rsa.getPublicKeyFromByteArray(key); publicKey = rsa.getPublicKeyFromByteArray(key);
} catch (...) { } catch (...) {
qCritical() << "error loading public key from environment variables"; qCritical() << "error loading public key from environment variables";
Utils::logException();
return ErrorCode::ApiMissingAgwPublicKey; return ErrorCode::ApiMissingAgwPublicKey;
} }
+19
View File
@@ -211,6 +211,25 @@ QString Utils::tun2socksPath()
#endif #endif
} }
void Utils::logException(const std::exception &e)
{
qCritical() << e.what();
try {
std::rethrow_if_nested(e);
} catch (const std::exception &nested) {
logException(nested);
} catch (...) {}
}
void Utils::logException(const std::exception_ptr &eptr)
{
try {
if (eptr) std::rethrow_exception(eptr);
} catch (const std::exception &e) {
logException(e);
} catch (...) {}
}
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// Inspired from http://stackoverflow.com/a/15281070/1529139 // Inspired from http://stackoverflow.com/a/15281070/1529139
// and http://stackoverflow.com/q/40059902/1529139 // and http://stackoverflow.com/q/40059902/1529139
+3
View File
@@ -34,6 +34,9 @@ public:
static QString certUtilPath(); static QString certUtilPath();
static QString tun2socksPath(); static QString tun2socksPath();
static void logException(const std::exception &e);
static void logException(const std::exception_ptr &eptr = std::current_exception());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
static bool signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent); static bool signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent);
#endif #endif