diff --git a/include/orm/utils/helpers.hpp b/include/orm/utils/helpers.hpp index 64cc5da34..b73061a4f 100644 --- a/include/orm/utils/helpers.hpp +++ b/include/orm/utils/helpers.hpp @@ -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 */ diff --git a/src/orm/utils/helpers.cpp b/src/orm/utils/helpers.cpp index d2d8e7bed..611633c74 100644 --- a/src/orm/utils/helpers.cpp +++ b/src/orm/utils/helpers.cpp @@ -1,6 +1,7 @@ #include "orm/utils/helpers.hpp" #include +#include #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