diff --git a/NOTES.txt b/NOTES.txt index ca2d467c2..5f7ab4ab7 100644 --- a/NOTES.txt +++ b/NOTES.txt @@ -117,8 +117,12 @@ RegExs: - const data members: (? -#include "orm/exceptions/invalidargumenterror.hpp" +#include "orm/exceptions/invalidtemplateargumenterror.hpp" #include "orm/tiny/concerns/hasrelationstore.hpp" #include "orm/tiny/exceptions/relationnotfounderror.hpp" #include "orm/tiny/exceptions/relationnotloadederror.hpp" @@ -931,7 +931,7 @@ namespace Concerns { if constexpr (std::is_same_v>) { if (!std::holds_alternative(relationVariant)) - throw Orm::Exceptions::RuntimeError( + throw Orm::Exceptions::InvalidTemplateArgumentError( QStringLiteral( "The relation '%1' is many type relation, use " "%2<%3>() method overload without an 'Orm::One' tag.") @@ -939,15 +939,14 @@ namespace Concerns Orm::Utils::Type::classPureBasename())); } else if constexpr (std::is_same_v>) { if (!std::holds_alternative(relationVariant)) - throw Orm::Exceptions::RuntimeError( + throw Orm::Exceptions::InvalidTemplateArgumentError( QStringLiteral( "The relation '%1' is one type relation, use " - "%2<%3, Orm::One>() method overload " - "with an 'Orm::One' tag.") + "%2<%3, Orm::One>() method overload with an 'Orm::One' tag.") .arg(relation, source, Orm::Utils::Type::classPureBasename())); } else - throw Orm::Exceptions::InvalidArgumentError( + throw Orm::Exceptions::InvalidTemplateArgumentError( "Unexpected 'Result' template argument."); } @@ -1126,7 +1125,7 @@ namespace Concerns ) relatedModel->touchOwners(); } else - throw Orm::Exceptions::RuntimeError( + throw Orm::Exceptions::InvalidTemplateArgumentError( "Bad relation type passed to the Model::touchOwnersVisited()."); } diff --git a/include/orm/tiny/tinybuilder.hpp b/include/orm/tiny/tinybuilder.hpp index c0fab141e..a087d602a 100644 --- a/include/orm/tiny/tinybuilder.hpp +++ b/include/orm/tiny/tinybuilder.hpp @@ -737,7 +737,7 @@ namespace Orm::Tiny const auto isSelectConstraint = relation.name.contains(COLON); if (isSelectConstraint && relation.constraints) - throw Orm::Exceptions::RuntimeError( + throw Orm::Exceptions::InvalidArgumentError( "Passing both 'Select constraint' and 'Lambda expression " "constraint' to the Model::with() method is not allowed, use " "only one of them."); diff --git a/src/orm/basegrammar.cpp b/src/orm/basegrammar.cpp index a028a69c1..0c83de54a 100644 --- a/src/orm/basegrammar.cpp +++ b/src/orm/basegrammar.cpp @@ -1,6 +1,7 @@ #include "orm/basegrammar.hpp" #include "orm/exceptions/runtimeerror.hpp" +#include "orm/utils/type.hpp" TINYORM_BEGIN_COMMON_NAMESPACE @@ -62,7 +63,9 @@ QString BaseGrammar::wrapTable(const QString &table) const QString BaseGrammar::wrapTable(const FromClause &table) const { if (std::holds_alternative(table)) - throw Exceptions::RuntimeError("std::monostate in wrapTable()."); + throw Exceptions::RuntimeError( + QStringLiteral("Unexpected std::monostate value in %1().") + .arg(__tiny_func__)); if (std::holds_alternative(table)) return getValue(std::get(table)).value(); diff --git a/src/orm/connectors/connector.cpp b/src/orm/connectors/connector.cpp index 88647b69e..5e7402760 100644 --- a/src/orm/connectors/connector.cpp +++ b/src/orm/connectors/connector.cpp @@ -47,7 +47,7 @@ Connector::createQSqlDatabaseConnection(const QString &name, const QVariantHash if (!db.open()) throw Exceptions::SqlError( - QStringLiteral("Open databse connection in %1() failed.") + QStringLiteral("Failed to open database connection in %1().") .arg(__tiny_func__), db.lastError()); diff --git a/src/orm/connectors/mysqlconnector.cpp b/src/orm/connectors/mysqlconnector.cpp index f0076990f..95e29d3ce 100644 --- a/src/orm/connectors/mysqlconnector.cpp +++ b/src/orm/connectors/mysqlconnector.cpp @@ -63,7 +63,7 @@ void MySqlConnector::parseConfigOptions(QVariantHash &options) const { // This connection options are banned static const QVariantHash banned { - // We have our reconnector + // We have our own reconnector {QStringLiteral("MYSQL_OPT_RECONNECT"), 1}, }; @@ -72,11 +72,13 @@ void MySqlConnector::parseConfigOptions(QVariantHash &options) const const auto &key = itOption.key(); const auto &value = itOption.value(); + // BUG rewrite silverqx if (options.contains(key) && options[key] == value) - throw std::domain_error( - "The connection option '" + value.value().toStdString() + - "' is not allowed in the TinyORM, TinyORM uses its own " - "reconnector."); + throw Exceptions::RuntimeError( + QStringLiteral( + "The connection option '%1' is not allowed in the TinyORM, " + "TinyORM uses its own reconnector.") + .arg(key)); ++itOption; } diff --git a/src/orm/databaseconnection.cpp b/src/orm/databaseconnection.cpp index 5ad3ac359..251cfdf80 100644 --- a/src/orm/databaseconnection.cpp +++ b/src/orm/databaseconnection.cpp @@ -240,7 +240,8 @@ QSqlQuery DatabaseConnection::unprepared(const QString &queryString) include the bindings with SQL, which will make this exception a lot more helpful to the developer instead of just the database's errors. */ throw Exceptions::QueryError( - QStringLiteral("Statement in %1() failed.").arg(functionName), + QStringLiteral("Unprepared statement in %1() failed.") + .arg(functionName), query); }); } @@ -360,7 +361,9 @@ bool DatabaseConnection::pingDatabase() void DatabaseConnection::reconnect() const { if (!m_reconnector) - throw std::runtime_error("Lost connection and no reconnector available."); + throw Exceptions::RuntimeError( + QStringLiteral("Lost connection and no reconnector available in %1.") + .arg(__tiny_func__)); std::invoke(m_reconnector, *this); } diff --git a/src/orm/databasemanager.cpp b/src/orm/databasemanager.cpp index dd3d9bbc0..a0aa170d6 100644 --- a/src/orm/databasemanager.cpp +++ b/src/orm/databasemanager.cpp @@ -1,6 +1,7 @@ #include "orm/databasemanager.hpp" #include "orm/concerns/hasconnectionresolver.hpp" +#include "orm/exceptions/invalidargumenterror.hpp" TINYORM_BEGIN_COMMON_NAMESPACE @@ -213,8 +214,9 @@ DatabaseManager & DatabaseManager::addConnection(const QVariantHash &config, const QString &name) { if ((*m_configuration).contains(name)) - throw Exceptions::RuntimeError( - QStringLiteral("The database connection '%1' already exists.").arg(name)); + throw Exceptions::InvalidArgumentError( + QStringLiteral("The database connection '%1' already exists.") + .arg(name)); (*m_configuration).insert(name, config); diff --git a/src/orm/query/querybuilder.cpp b/src/orm/query/querybuilder.cpp index 3a9b3e0b1..be1b7432d 100644 --- a/src/orm/query/querybuilder.cpp +++ b/src/orm/query/querybuilder.cpp @@ -535,7 +535,7 @@ Builder &Builder::orderBy(const Column &column, const QString &direction) const auto &directionLower = direction.toLower(); if (directionLower != ASC && directionLower != DESC) - throw Exceptions::RuntimeError( + throw Exceptions::InvalidArgumentError( R"T(Order direction must be "asc" or "desc", case is not important.)T"); m_orders.append({column, directionLower}); diff --git a/src/orm/support/configurationoptionsparser.cpp b/src/orm/support/configurationoptionsparser.cpp index 6e6d7d004..31268c8be 100644 --- a/src/orm/support/configurationoptionsparser.cpp +++ b/src/orm/support/configurationoptionsparser.cpp @@ -1,9 +1,8 @@ #include "orm/support/configurationoptionsparser.hpp" -#include - #include "orm/connectors/connector.hpp" #include "orm/constants.hpp" +#include "orm/exceptions/runtimeerror.hpp" using Orm::Constants::EQ_C; using Orm::Constants::options_; @@ -53,9 +52,9 @@ ConfigurationOptionsParser::validateConfigOptions(const QVariant &options) const #endif && !options.canConvert() ) - throw std::domain_error( - "The unsupported 'options' type in the connection configuration " - "has to be QString or QVariantHash."); + throw Exceptions::RuntimeError( + "Passed unsupported 'options' type in the connection configuration, " + "it has to be the QString or QVariantHash type."); } QVariantHash diff --git a/tests/TinyUtils/src/databases.cpp b/tests/TinyUtils/src/databases.cpp index 564b3aa89..6d68f24af 100644 --- a/tests/TinyUtils/src/databases.cpp +++ b/tests/TinyUtils/src/databases.cpp @@ -2,7 +2,6 @@ #include "orm/constants.hpp" #include "orm/db.hpp" -#include "orm/exceptions/logicerror.hpp" #include "orm/exceptions/runtimeerror.hpp" using Orm::Constants::database_; @@ -35,7 +34,6 @@ using Orm::Constants::UTF8MB4; using Orm::DB; -using Orm::Exceptions::LogicError; using Orm::Exceptions::RuntimeError; namespace TestUtils @@ -225,8 +223,8 @@ void Databases::throwIfConnectionsInitialized() static bool initialized = false; if (initialized) - throw LogicError("Databases::createConnections/createConnection methods " - "can be called only once."); + throw RuntimeError("Databases::createConnections/createConnection methods " + "can be called only once."); initialized = true; }