1
0
Fork 0

More userfriendly errormessages if creating the transaction fails.

This commit is contained in:
Willi Goesgens 2014-09-08 15:07:05 +02:00
parent 68d30cef8b
commit 6e1fbbddfc
2 changed files with 31 additions and 3 deletions

View File

@ -219,7 +219,7 @@ QueryResult Query::execute () {
int res = trx.begin();
if (res != TRI_ERROR_NO_ERROR) {
return QueryResult(res, TRI_errno_string(res));
return transactionError(res, trx);
}
plan = ExecutionPlan::instanciateFromAst(parser.ast());
@ -243,7 +243,7 @@ QueryResult Query::execute () {
int res = trx.begin();
if (res != TRI_ERROR_NO_ERROR) {
return QueryResult(res, TRI_errno_string(res));
return transactionError(res, trx);
}
}
@ -368,7 +368,7 @@ QueryResult Query::explain () {
int res = trx.begin();
if (res != TRI_ERROR_NO_ERROR) {
return QueryResult(res, TRI_errno_string(res));
return transactionError(res, trx);
}
plan = ExecutionPlan::instanciateFromAst(parser.ast());
@ -482,6 +482,26 @@ char* Query::registerString (std::string const& p,
// --SECTION-- private methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief neatly format transaction errors to the user.
////////////////////////////////////////////////////////////////////////////////
QueryResult Query::transactionError (int errorCode, AQL_TRANSACTION_V8 const& trx)
{
std::string err;
err += std::string(TRI_errno_string(errorCode));
auto detail = trx.getErrorData();
if (detail.size() > 0) {
err += std::string(" (") + detail + std::string(")");
}
err += std::string("\nwhile executing:\n") + _queryString + std::string("\n");
return QueryResult(errorCode, err);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief read the "optimizer.rules" section from the options
////////////////////////////////////////////////////////////////////////////////

View File

@ -35,6 +35,8 @@
#include "Aql/BindParameters.h"
#include "Aql/Collections.h"
#include "Aql/QueryResult.h"
#include "Utils/AqlTransaction.h"
#include "Utils/V8TransactionContext.h"
struct TRI_json_s;
struct TRI_vocbase_s;
@ -218,6 +220,12 @@ namespace triagens {
std::vector<std::string> getRulesFromOptions () const;
////////////////////////////////////////////////////////////////////////////////
/// @brief neatly format transaction errors to the user.
////////////////////////////////////////////////////////////////////////////////
QueryResult transactionError (int errorCode, AQL_TRANSACTION_V8 const& trx);
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------