mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-01-06 02:49:31 -06:00
enhanced Helpers::logException()
Log the QLibraryInfo::PluginsPath if an exception message contains: QSqlError(Driver not loaded, Driver not loaded).
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user