enhanced Helpers::logException()

Log the QLibraryInfo::PluginsPath if an exception message contains:
QSqlError(Driver not loaded, Driver not loaded).
This commit is contained in:
silverqx
2023-09-05 17:49:37 +02:00
parent f1dbd13076
commit ffd3817380
2 changed files with 33 additions and 1 deletions

View File

@@ -93,6 +93,12 @@ namespace Utils
/*! Set the QDateTime's time zone according to the given connection. */
static QDateTime
setTimeZone(QDateTime &&datetime, const QString &connection = "");
private:
/*! Log the QLibraryInfo::PluginsPath if an exception message contains:
QSqlError(Driver not loaded, Driver not loaded). */
[[maybe_unused]]
static void logPluginsPath(const QString &exceptionMessage);
};
/* public */

View File

@@ -1,6 +1,7 @@
#include "orm/utils/helpers.hpp"
#include <QDebug>
#include <QLibraryInfo>
#include "orm/db.hpp"
#include "orm/macros/likely.hpp"
@@ -28,10 +29,16 @@ int Helpers::qVariantTypeId(const QVariant &value)
void Helpers::logException(const std::exception &e, const bool fatal)
{
const QString exceptionMessage(e.what());
/* Log the QLibraryInfo::PluginsPath if an exception message contains:
QSqlError(Driver not loaded, Driver not loaded). */
logPluginsPath(exceptionMessage);
const auto message = QStringLiteral("\nCaught '")
.append(TypeUtils::classPureBasename(e, true))
.append(QStringLiteral("' Exception:\n"))
.append(e.what())
.append(exceptionMessage)
.append(QChar(QChar::LineFeed));
if (fatal)
@@ -148,6 +155,25 @@ QDateTime Helpers::setTimeZone(QDateTime &&datetime, const QString &connection)
return setTimeZone(datetime, connection);
}
/* private */
void Helpers::logPluginsPath(const QString &exceptionMessage)
{
const static auto
DriverNotFound = QStringLiteral("QSqlError(Driver not loaded, Driver not loaded)");
// Nothing to do
if (!exceptionMessage.contains(DriverNotFound, Qt::CaseInsensitive))
return;
qInfo().nospace() << "Plugins Path: "
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
<< QLibraryInfo::path(QLibraryInfo::PluginsPath);
#else
<< QLibraryInfo::location(QLibraryInfo::PluginsPath);
#endif
}
} // namespace Orm::Utils
TINYORM_END_COMMON_NAMESPACE