diff --git a/arangod/Aql/Ast.cpp b/arangod/Aql/Ast.cpp index 5c697a5e43..d120bef01e 100644 --- a/arangod/Aql/Ast.cpp +++ b/arangod/Aql/Ast.cpp @@ -32,7 +32,7 @@ #include "Aql/Collection.h" #include "Aql/Executor.h" #include "Basics/tri-strings.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/collection.h" using namespace triagens::aql; diff --git a/arangod/Aql/AstNode.h b/arangod/Aql/AstNode.h index f38d5156f4..deb89d922d 100644 --- a/arangod/Aql/AstNode.h +++ b/arangod/Aql/AstNode.h @@ -31,10 +31,10 @@ #define ARANGODB_AQL_ASTNODE_H 1 #include "Basics/Common.h" +#include "Basics/Exceptions.h" #include "Basics/json.h" #include "Basics/vector.h" #include "Basics/JsonHelper.h" -#include "Utils/Exception.h" #include "Aql/Query.h" namespace triagens { diff --git a/arangod/Aql/BindParameters.cpp b/arangod/Aql/BindParameters.cpp index 3b777133d7..f5aabb12f8 100644 --- a/arangod/Aql/BindParameters.cpp +++ b/arangod/Aql/BindParameters.cpp @@ -29,7 +29,7 @@ #include "Aql/BindParameters.h" #include "Basics/json.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; diff --git a/arangod/Aql/Collection.cpp b/arangod/Aql/Collection.cpp index 99ec960d70..c0e7858229 100644 --- a/arangod/Aql/Collection.cpp +++ b/arangod/Aql/Collection.cpp @@ -30,10 +30,10 @@ #include "Collection.h" #include "Aql/ExecutionEngine.h" #include "Basics/StringUtils.h" +#include "Basics/Exceptions.h" #include "Cluster/ClusterInfo.h" #include "Cluster/ClusterMethods.h" #include "Cluster/ServerState.h" -#include "Utils/Exception.h" #include "VocBase/document-collection.h" #include "VocBase/transaction.h" #include "VocBase/vocbase.h" diff --git a/arangod/Aql/Collections.h b/arangod/Aql/Collections.h index de250e4ecc..8ca5c4717d 100644 --- a/arangod/Aql/Collections.h +++ b/arangod/Aql/Collections.h @@ -31,8 +31,8 @@ #define ARANGODB_AQL_COLLECTIONS_H 1 #include "Basics/Common.h" +#include "Basics/Exceptions.h" #include "Aql/Collection.h" -#include "Utils/Exception.h" struct TRI_vocbase_s; diff --git a/arangod/Aql/ExecutionBlock.cpp b/arangod/Aql/ExecutionBlock.cpp index 1aa12f7ae6..f4772ac377 100644 --- a/arangod/Aql/ExecutionBlock.cpp +++ b/arangod/Aql/ExecutionBlock.cpp @@ -32,8 +32,8 @@ #include "Basics/StringUtils.h" #include "Basics/StringBuffer.h" #include "Basics/json-utilities.h" +#include "Basics/Exceptions.h" #include "HashIndex/hash-index.h" -#include "Utils/Exception.h" #include "V8/v8-globals.h" #include "VocBase/edge-collection.h" #include "VocBase/index.h" diff --git a/arangod/Aql/ExecutionEngine.cpp b/arangod/Aql/ExecutionEngine.cpp index e4f2a9336e..32911e8b99 100644 --- a/arangod/Aql/ExecutionEngine.cpp +++ b/arangod/Aql/ExecutionEngine.cpp @@ -34,7 +34,7 @@ #include "Aql/QueryRegistry.h" #include "Aql/WalkerWorker.h" #include "Cluster/ClusterComm.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "Basics/logging.h" using namespace triagens::aql; diff --git a/arangod/Aql/ExecutionPlan.cpp b/arangod/Aql/ExecutionPlan.cpp index da358f92df..81e50fc417 100644 --- a/arangod/Aql/ExecutionPlan.cpp +++ b/arangod/Aql/ExecutionPlan.cpp @@ -38,7 +38,7 @@ #include "Aql/Variable.h" #include "Aql/WalkerWorker.h" #include "Basics/JsonHelper.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; using namespace triagens::basics; diff --git a/arangod/Aql/ExecutionStats.cpp b/arangod/Aql/ExecutionStats.cpp index fd42769adb..c05167a88f 100644 --- a/arangod/Aql/ExecutionStats.cpp +++ b/arangod/Aql/ExecutionStats.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "Aql/ExecutionStats.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; using Json = triagens::basics::Json; diff --git a/arangod/Aql/Executor.cpp b/arangod/Aql/Executor.cpp index 59382773a5..cf14d51198 100644 --- a/arangod/Aql/Executor.cpp +++ b/arangod/Aql/Executor.cpp @@ -33,7 +33,7 @@ #include "Aql/V8Expression.h" #include "Aql/Variable.h" #include "Basics/StringBuffer.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "V8/v8-conv.h" #include "V8/v8-globals.h" diff --git a/arangod/Aql/Expression.cpp b/arangod/Aql/Expression.cpp index c9a03359e7..99f5e21b55 100644 --- a/arangod/Aql/Expression.cpp +++ b/arangod/Aql/Expression.cpp @@ -38,7 +38,7 @@ #include "Basics/json.h" #include "ShapedJson/shaped-json.h" #include "VocBase/document-collection.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; using Json = triagens::basics::Json; @@ -169,7 +169,7 @@ AqlValue Expression::execute (triagens::arango::AqlTransaction* trx, // std::cout << triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, _node->toJson(TRI_UNKNOWN_MEM_ZONE, true)).toString()<< "\n"; return _func->execute(isolate, _ast->query(), trx, docColls, argv, startPos, vars, regs); } - catch (triagens::arango::Exception& ex) { + catch (triagens::basics::Exception& ex) { if (_ast->query()->verboseErrors()) { ex.addToMessage(" while evaluating expression "); auto json = _node->toJson(TRI_UNKNOWN_MEM_ZONE, false); diff --git a/arangod/Aql/Function.cpp b/arangod/Aql/Function.cpp index 544f68b1e9..90ac9a08c4 100644 --- a/arangod/Aql/Function.cpp +++ b/arangod/Aql/Function.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "Aql/Function.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index 0708714fad..b11deadca0 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -30,7 +30,7 @@ #include "Aql/Functions.h" #include "Basics/fpconv.h" #include "Basics/JsonHelper.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; using Json = triagens::basics::Json; diff --git a/arangod/Aql/Index.h b/arangod/Aql/Index.h index e8977851a5..9a7c593095 100644 --- a/arangod/Aql/Index.h +++ b/arangod/Aql/Index.h @@ -31,10 +31,10 @@ #define ARANGODB_AQL_INDEX_H 1 #include "Basics/Common.h" +#include "Basics/Exceptions.h" #include "Basics/json.h" #include "Basics/JsonHelper.h" #include "HashIndex/hash-index.h" -#include "Utils/Exception.h" #include "VocBase/index.h" namespace triagens { diff --git a/arangod/Aql/Query.cpp b/arangod/Aql/Query.cpp index 8bebfe7675..cd2fb81d53 100644 --- a/arangod/Aql/Query.cpp +++ b/arangod/Aql/Query.cpp @@ -38,10 +38,10 @@ #include "Basics/JsonHelper.h" #include "Basics/json.h" #include "Basics/tri-strings.h" +#include "Basics/Exceptions.h" #include "Cluster/ServerState.h" #include "Utils/AqlTransaction.h" #include "Utils/CollectionNameResolver.h" -#include "Utils/Exception.h" #include "Utils/StandaloneTransactionContext.h" #include "Utils/V8TransactionContext.h" #include "V8Server/ApplicationV8.h" @@ -597,7 +597,7 @@ QueryResult Query::prepare (QueryRegistry* registry) { _engine = engine; return QueryResult(); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { cleanupPlanAndEngine(ex.code()); return QueryResult(ex.code(), ex.message() + getStateString()); } @@ -667,7 +667,7 @@ QueryResult Query::execute (QueryRegistry* registry) { return result; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { cleanupPlanAndEngine(ex.code()); return QueryResult(ex.code(), ex.message() + getStateString()); } @@ -739,7 +739,7 @@ QueryResultV8 Query::executeV8 (v8::Isolate* isolate, QueryRegistry* registry) { return result; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { cleanupPlanAndEngine(ex.code()); return QueryResultV8(ex.code(), ex.message() + getStateString()); } @@ -766,7 +766,7 @@ QueryResult Query::parse () { Parser parser(this); return parser.parse(true); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return QueryResult(ex.code(), ex.message()); } catch (...) { @@ -854,7 +854,7 @@ QueryResult Query::explain () { return result; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return QueryResult(ex.code(), ex.message() + getStateString()); } catch (std::bad_alloc const&) { diff --git a/arangod/Aql/QueryList.cpp b/arangod/Aql/QueryList.cpp index c284a3551b..60d2e8b93f 100644 --- a/arangod/Aql/QueryList.cpp +++ b/arangod/Aql/QueryList.cpp @@ -32,7 +32,7 @@ #include "Basics/logging.h" #include "Basics/ReadLocker.h" #include "Basics/WriteLocker.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/vocbase.h" using namespace triagens::aql; diff --git a/arangod/Aql/RestAqlHandler.cpp b/arangod/Aql/RestAqlHandler.cpp index d4ea4f9a50..0d901b032a 100644 --- a/arangod/Aql/RestAqlHandler.cpp +++ b/arangod/Aql/RestAqlHandler.cpp @@ -434,7 +434,7 @@ void RestAqlHandler::useQuery (std::string const& operation, } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { _queryRegistry->close(_vocbase, _qId); generateError(HttpResponse::SERVER_ERROR, ex.code(), @@ -549,7 +549,7 @@ void RestAqlHandler::getInfoQuery (std::string const& operation, return; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { _queryRegistry->close(_vocbase, _qId); LOG_ERROR("failed during use of query: %s", ex.message().c_str()); generateError(HttpResponse::SERVER_ERROR, diff --git a/arangod/Aql/Scopes.cpp b/arangod/Aql/Scopes.cpp index 24feeac63b..00e77a730c 100644 --- a/arangod/Aql/Scopes.cpp +++ b/arangod/Aql/Scopes.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "Aql/Scopes.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; diff --git a/arangod/Aql/VariableGenerator.cpp b/arangod/Aql/VariableGenerator.cpp index 1ee83e41e8..49dde4ce6a 100644 --- a/arangod/Aql/VariableGenerator.cpp +++ b/arangod/Aql/VariableGenerator.cpp @@ -27,8 +27,8 @@ /// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#include "Utils/Exception.h" #include "Aql/VariableGenerator.h" +#include "Basics/Exceptions.h" using namespace triagens::aql; using Json = triagens::basics::Json; diff --git a/arangod/CMakeLists.txt b/arangod/CMakeLists.txt index 64f15b8931..5dd268f0ed 100644 --- a/arangod/CMakeLists.txt +++ b/arangod/CMakeLists.txt @@ -115,7 +115,6 @@ add_executable( RestServer/arangod.cpp SkipLists/skiplistIndex.cpp Utils/DocumentHelper.cpp - Utils/Exception.cpp Utils/StandaloneTransactionContext.cpp Utils/Transaction.cpp Utils/TransactionContext.cpp diff --git a/arangod/CapConstraint/cap-constraint.cpp b/arangod/CapConstraint/cap-constraint.cpp index cf1abe318f..4dcf6facbf 100644 --- a/arangod/CapConstraint/cap-constraint.cpp +++ b/arangod/CapConstraint/cap-constraint.cpp @@ -31,7 +31,7 @@ #include "Basics/logging.h" #include "Basics/tri-strings.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "Utils/transactions.h" #include "VocBase/document-collection.h" #include "VocBase/headers.h" diff --git a/arangod/Makefile.files b/arangod/Makefile.files index 92d63abf87..6616eb7f33 100644 --- a/arangod/Makefile.files +++ b/arangod/Makefile.files @@ -89,7 +89,6 @@ arangod_libarangod_a_SOURCES = \ arangod/RestServer/arangod.cpp \ arangod/SkipLists/skiplistIndex.cpp \ arangod/Utils/DocumentHelper.cpp \ - arangod/Utils/Exception.cpp \ arangod/Utils/StandaloneTransactionContext.cpp \ arangod/Utils/Transaction.cpp \ arangod/Utils/TransactionContext.cpp \ diff --git a/arangod/Replication/ContinuousSyncer.cpp b/arangod/Replication/ContinuousSyncer.cpp index 0c62a33518..ddd5a17e7e 100644 --- a/arangod/Replication/ContinuousSyncer.cpp +++ b/arangod/Replication/ContinuousSyncer.cpp @@ -29,6 +29,7 @@ #include "ContinuousSyncer.h" +#include "Basics/Exceptions.h" #include "Basics/json.h" #include "Basics/JsonHelper.h" #include "Basics/StringBuffer.h" @@ -38,7 +39,6 @@ #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" #include "Utils/CollectionGuard.h" -#include "Utils/Exception.h" #include "Utils/transactions.h" #include "VocBase/document-collection.h" #include "VocBase/transaction.h" @@ -647,7 +647,7 @@ int ContinuousSyncer::changeCollection (TRI_json_t const* json) { bool doSync = _vocbase->_settings.forceSyncProperties; return TRI_UpdateCollectionInfo(_vocbase, guard.collection()->_collection, ¶meters, doSync); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { diff --git a/arangod/Replication/InitialSyncer.cpp b/arangod/Replication/InitialSyncer.cpp index fab84d756f..3d42a2edb7 100644 --- a/arangod/Replication/InitialSyncer.cpp +++ b/arangod/Replication/InitialSyncer.cpp @@ -29,6 +29,7 @@ #include "InitialSyncer.h" +#include "Basics/Exceptions.h" #include "Basics/json.h" #include "Basics/logging.h" #include "Basics/tri-strings.h" @@ -37,7 +38,6 @@ #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" #include "Utils/CollectionGuard.h" -#include "Utils/Exception.h" #include "Utils/transactions.h" #include "VocBase/index.h" #include "VocBase/document-collection.h" @@ -858,7 +858,7 @@ int InitialSyncer::handleCollection (TRI_json_t const* parameters, TRI_WRITE_UNLOCK_DOCUMENTS_INDEXES_PRIMARY_COLLECTION(document); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/Replication/Syncer.cpp b/arangod/Replication/Syncer.cpp index bfbef7ecd5..10d6795e98 100644 --- a/arangod/Replication/Syncer.cpp +++ b/arangod/Replication/Syncer.cpp @@ -33,13 +33,13 @@ #include "Basics/json.h" #include "Basics/tri-strings.h" #include "Basics/JsonHelper.h" +#include "Basics/Exceptions.h" #include "Rest/HttpRequest.h" #include "SimpleHttpClient/GeneralClientConnection.h" #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" #include "Utils/CollectionGuard.h" #include "Utils/DocumentHelper.h" -#include "Utils/Exception.h" #include "Utils/transactions.h" #include "VocBase/collection.h" #include "VocBase/document-collection.h" @@ -291,7 +291,7 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti return res; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -313,7 +313,7 @@ int Syncer::applyCollectionDumpMarker (TRI_transaction_collection_t* trxCollecti res = TRI_ERROR_NO_ERROR; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -501,7 +501,7 @@ int Syncer::createIndex (TRI_json_t const* json) { return res; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -542,7 +542,7 @@ int Syncer::dropIndex (TRI_json_t const* json) { return TRI_ERROR_NO_ERROR; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { diff --git a/arangod/RestHandler/RestPleaseUpgradeHandler.cpp b/arangod/RestHandler/RestPleaseUpgradeHandler.cpp index 0276572801..dbe34fb48c 100644 --- a/arangod/RestHandler/RestPleaseUpgradeHandler.cpp +++ b/arangod/RestHandler/RestPleaseUpgradeHandler.cpp @@ -83,7 +83,14 @@ HttpHandler::status_t RestPleaseUpgradeHandler::execute () { /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// -void RestPleaseUpgradeHandler::handleError (TriagensError const&) { +void RestPleaseUpgradeHandler::handleError (const TriagensError&) { +} + +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + +void RestPleaseUpgradeHandler::handleError (const Exception&) { } // ----------------------------------------------------------------------------- diff --git a/arangod/RestHandler/RestPleaseUpgradeHandler.h b/arangod/RestHandler/RestPleaseUpgradeHandler.h index 6ca72b9af9..d938919b18 100644 --- a/arangod/RestHandler/RestPleaseUpgradeHandler.h +++ b/arangod/RestHandler/RestPleaseUpgradeHandler.h @@ -81,7 +81,13 @@ namespace triagens { /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// - void handleError (basics::TriagensError const&); + void handleError (const basics::TriagensError&); + +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + + void handleError (const basics::Exception&); }; } } diff --git a/arangod/RestHandler/RestQueryHandler.cpp b/arangod/RestHandler/RestQueryHandler.cpp index b97cb31ae9..f8170ac50c 100644 --- a/arangod/RestHandler/RestQueryHandler.cpp +++ b/arangod/RestHandler/RestQueryHandler.cpp @@ -132,6 +132,9 @@ bool RestQueryHandler::readQueryProperties () { catch (const TriagensError& err) { handleError(err); } + catch (const Exception& err) { + handleError(err); + } catch (std::exception const& ex) { triagens::basics::InternalError err(ex, __FILE__, __LINE__); handleError(err); @@ -174,6 +177,9 @@ bool RestQueryHandler::readQuery (bool slow) { catch (const TriagensError& err) { handleError(err); } + catch (const Exception& err) { + handleError(err); + } catch (std::exception const& ex) { triagens::basics::InternalError err(ex, __FILE__, __LINE__); handleError(err); @@ -197,7 +203,7 @@ bool RestQueryHandler::readQuery () { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "expecting GET /_api/query/"); - return false; + return true; } const auto& name = suffix[0]; @@ -215,7 +221,7 @@ bool RestQueryHandler::readQuery () { generateError(HttpResponse::NOT_FOUND, TRI_ERROR_HTTP_NOT_FOUND, "unknown type '" + name + "', expecting 'slow', 'current', or 'properties'"); - return false; + return true; } //////////////////////////////////////////////////////////////////////////////// @@ -276,7 +282,7 @@ bool RestQueryHandler::deleteQuery () { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "expecting DELETE /_api/query/ or /_api/query/slow"); - return false; + return true; } const auto& name = suffix[0]; @@ -300,16 +306,14 @@ bool RestQueryHandler::replaceProperties () { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "expecting PUT /_api/query/properties"); - return false; - } - - TRI_json_t* json = parseJsonBody(); - - if (json == nullptr) { return true; } - if (JsonHelper::isObject(json)) { + unique_ptr body(parseJsonBody()); + + if (body == nullptr) { + // error message generated in parseJsonBody + return true; } auto queryList = static_cast(_vocbase->_queries); @@ -323,24 +327,24 @@ bool RestQueryHandler::replaceProperties () { // TODO(fc) add a "hasSomething" to JsonHelper? - if (JsonHelper::getObjectElement(json, "enabled") != nullptr) { - enabled = JsonHelper::checkAndGetBooleanValue(json, "enabled"); + if (JsonHelper::getObjectElement(body.get(), "enabled") != nullptr) { + enabled = JsonHelper::checkAndGetBooleanValue(body.get(), "enabled"); } - if (JsonHelper::getObjectElement(json, "trackSlowQueries") != nullptr) { - trackSlowQueries = JsonHelper::checkAndGetBooleanValue(json, "trackSlowQueries"); + if (JsonHelper::getObjectElement(body.get(), "trackSlowQueries") != nullptr) { + trackSlowQueries = JsonHelper::checkAndGetBooleanValue(body.get(), "trackSlowQueries"); } - if (JsonHelper::getObjectElement(json, "maxSlowQueries") != nullptr) { - maxSlowQueries = JsonHelper::checkAndGetNumericValue(json, "maxSlowQueries"); + if (JsonHelper::getObjectElement(body.get(), "maxSlowQueries") != nullptr) { + maxSlowQueries = JsonHelper::checkAndGetNumericValue(body.get(), "maxSlowQueries"); } - if (JsonHelper::getObjectElement(json, "slowQueryThreshold") != nullptr) { - slowQueryThreshold = JsonHelper::checkAndGetNumericValue(json, "slowQueryThreshold"); + if (JsonHelper::getObjectElement(body.get(), "slowQueryThreshold") != nullptr) { + slowQueryThreshold = JsonHelper::checkAndGetNumericValue(body.get(), "slowQueryThreshold"); } - if (JsonHelper::getObjectElement(json, "maxQueryStringLength") != nullptr) { - maxQueryStringLength = JsonHelper::checkAndGetNumericValue(json, "maxQueryStringLength"); + if (JsonHelper::getObjectElement(body.get(), "maxQueryStringLength") != nullptr) { + maxQueryStringLength = JsonHelper::checkAndGetNumericValue(body.get(), "maxQueryStringLength"); } queryList->enabled(enabled); @@ -354,6 +358,9 @@ bool RestQueryHandler::replaceProperties () { catch (const TriagensError& err) { handleError(err); } + catch (const Exception& err) { + handleError(err); + } catch (std::exception const& ex) { triagens::basics::InternalError err(ex, __FILE__, __LINE__); handleError(err); @@ -377,18 +384,18 @@ bool RestQueryHandler::parseQuery () { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER, "expecting POST /_api/query"); - return false; + return true; } - TRI_json_t* body = parseJsonBody(); + unique_ptr body(parseJsonBody()); - if (body == nullptr) { - TRI_FreeJson(TRI_CORE_MEM_ZONE, body); + if (body.get() == nullptr) { + // error message generated in parseJsonBody return true; } try { - const string&& queryString = JsonHelper::checkAndGetStringValue(body, "query"); + const string&& queryString = JsonHelper::checkAndGetStringValue(body.get(), "query"); Query query(_applicationV8, true, _vocbase, queryString.c_str(), queryString.size(), nullptr, nullptr, PART_MAIN); @@ -435,6 +442,9 @@ bool RestQueryHandler::parseQuery () { catch (const TriagensError& err) { handleError(err); } + catch (const Exception& err) { + handleError(err); + } catch (std::exception const& ex) { triagens::basics::InternalError err(ex, __FILE__, __LINE__); handleError(err); diff --git a/arangod/RestHandler/RestReplicationHandler.cpp b/arangod/RestHandler/RestReplicationHandler.cpp index 136a31b62f..4bc60dce75 100644 --- a/arangod/RestHandler/RestReplicationHandler.cpp +++ b/arangod/RestHandler/RestReplicationHandler.cpp @@ -1073,7 +1073,7 @@ void RestReplicationHandler::handleCommandLoggerFollow () { insertClient(dump._lastFoundTick); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -1987,7 +1987,7 @@ int RestReplicationHandler::processRestoreIndexes (TRI_json_t const* collection, } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { errorMsg = "could not create index: " + string(TRI_errno_string(ex.code())); } catch (...) { @@ -2161,7 +2161,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co return res; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { TRI_FreeShapedJson(zone, shaped); return ex.code(); } @@ -2186,7 +2186,7 @@ int RestReplicationHandler::applyCollectionDumpMarker (CollectionNameResolver co res = TRI_ERROR_NO_ERROR; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -2960,7 +2960,7 @@ void RestReplicationHandler::handleCommandDump () { // avoid double freeing TRI_StealStringBuffer(dump._buffer); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/Utils/CollectionGuard.h b/arangod/Utils/CollectionGuard.h index cc00c9eaee..10973fb626 100644 --- a/arangod/Utils/CollectionGuard.h +++ b/arangod/Utils/CollectionGuard.h @@ -31,7 +31,7 @@ #define ARANGODB_UTILS_COLLECTION_GUARD_H 1 #include "Basics/Common.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/vocbase.h" namespace triagens { diff --git a/arangod/Utils/DatabaseGuard.h b/arangod/Utils/DatabaseGuard.h index bd99df8841..447e289144 100644 --- a/arangod/Utils/DatabaseGuard.h +++ b/arangod/Utils/DatabaseGuard.h @@ -31,7 +31,7 @@ #define ARANGODB_UTILS_DATABASE_GUARD_H 1 #include "Basics/Common.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/server.h" struct TRI_vocbase_s; diff --git a/arangod/Utils/Exception.cpp b/arangod/Utils/Exception.cpp deleted file mode 100644 index 94c376909c..0000000000 --- a/arangod/Utils/Exception.cpp +++ /dev/null @@ -1,188 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief arango exceptions -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Jan Steemann -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany -/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#include "Exception.h" -#include "Basics/StringUtils.h" - -using namespace std; -using namespace triagens::arango; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief controls if backtraces are printed with exceptions -//////////////////////////////////////////////////////////////////////////////// - -static bool WithBackTrace = false; - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructor, without format string -//////////////////////////////////////////////////////////////////////////////// - -Exception::Exception (int code, - char const* file, - int line) - : _errorMessage(TRI_errno_string(code)), - _file(file), - _line(line), - _code(code) { -#ifdef TRI_ENABLE_MAINTAINER_MODE -#if HAVE_BACKTRACE - if (WithBackTrace) { - _errorMessage += std::string("\n\n"); - TRI_GetBacktrace(_errorMessage); - _errorMessage += std::string("\n\n"); - } -#endif -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief constructor, for creating an exception with an already created -/// error message (normally based on error templates containing %s, %d etc.) -//////////////////////////////////////////////////////////////////////////////// - -Exception::Exception (int code, - string const& errorMessage, - char const* file, - int line) - : _errorMessage(errorMessage), - _file(file), - _line(line), - _code(code) { - -#ifdef TRI_ENABLE_MAINTAINER_MODE -#if HAVE_BACKTRACE - if (WithBackTrace) { - _errorMessage += std::string("\n\n"); - TRI_GetBacktrace(_errorMessage); - _errorMessage += std::string("\n\n"); - } -#endif -#endif -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief destructor -//////////////////////////////////////////////////////////////////////////////// - -Exception::~Exception () throw () { -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief return exception message -//////////////////////////////////////////////////////////////////////////////// - -char const* Exception::what () const throw () { - // we have to use an instance member here because we should not return a - // pointer (c_str()) to the internals of a stack object (stack object will - // be destroyed when function is left...) - // additionally, we should not create new string values here as this might - // throw exceptions - but this function is marked to throw no exceptions! - /* - std::string message = "exception in '"; - message.append(_file); - message.append("' at line "); - message.append(basics::StringUtils::itoa(_line)); - message.append(": "); - message += this->message(); - - return message.c_str(); - */ - - return _errorMessage.c_str(); -} - - - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief construct an error message from a template string -//////////////////////////////////////////////////////////////////////////////// - -std::string Exception::FillExceptionString (int code, - ...) { - char const* format = TRI_errno_string(code); - TRI_ASSERT(format != nullptr); - -#ifdef TRI_ENABLE_MAINTAINER_MODE - // Obviously the formatstring of the error code has to support parameters. - TRI_ASSERT(strchr(format, '%') != nullptr); -#endif - - char buffer[1024]; - va_list ap; - va_start(ap, code); - vsnprintf(buffer, sizeof(buffer) - 1, format, ap); - va_end(ap); - buffer[sizeof(buffer) - 1] = '\0'; // Windows - - return std::string(buffer); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief construct an error message from a template string -//////////////////////////////////////////////////////////////////////////////// - -std::string Exception::FillFormatExceptionString (char const* format, - ...) { - TRI_ASSERT(format != nullptr); - -#ifdef TRI_ENABLE_MAINTAINER_MODE - // Format #1 should come from the macro... - TRI_ASSERT(strchr(format, '%') != nullptr); - // Obviously the user has to give us a format string. - TRI_ASSERT(strchr(strchr(format, '%'), '%') != nullptr); -#endif - - char buffer[1024]; - va_list ap; - va_start(ap, format); - vsnprintf(buffer, sizeof(buffer) - 1, format, ap); - va_end(ap); - buffer[sizeof(buffer) - 1] = '\0'; // Windows - - return std::string(buffer); -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief controls whether a backtrace is created for each exception -//////////////////////////////////////////////////////////////////////////////// - -void Exception::SetVerbose (bool verbose) { - WithBackTrace = verbose; -} - -// ----------------------------------------------------------------------------- -// --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- - -// Local Variables: -// mode: outline-minor -// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" -// End: diff --git a/arangod/Utils/Exception.h b/arangod/Utils/Exception.h deleted file mode 100644 index a4e8fa98fd..0000000000 --- a/arangod/Utils/Exception.h +++ /dev/null @@ -1,151 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// @brief arango exceptions -/// -/// @file -/// -/// DISCLAIMER -/// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany -/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany -/// -/// Licensed under the Apache License, Version 2.0 (the "License"); -/// you may not use this file except in compliance with the License. -/// You may obtain a copy of the License at -/// -/// http://www.apache.org/licenses/LICENSE-2.0 -/// -/// Unless required by applicable law or agreed to in writing, software -/// distributed under the License is distributed on an "AS IS" BASIS, -/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -/// See the License for the specific language governing permissions and -/// limitations under the License. -/// -/// Copyright holder is ArangoDB GmbH, Cologne, Germany -/// -/// @author Jan Steemann -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany -/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany -//////////////////////////////////////////////////////////////////////////////// - -#ifndef ARANGODB_UTILS_EXCEPTION_H -#define ARANGODB_UTILS_EXCEPTION_H 1 - -#include "Basics/Common.h" -#include "Basics/Exceptions.h" - -#include - -// ----------------------------------------------------------------------------- -// --SECTION-- public macros -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an arango exception with an error code -//////////////////////////////////////////////////////////////////////////////// - -#define THROW_ARANGO_EXCEPTION(code) \ - throw triagens::arango::Exception(code, __FILE__, __LINE__) - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an arango exception with an error code and arbitrary -/// arguments (to be inserted in printf-style manner) -//////////////////////////////////////////////////////////////////////////////// - -#define THROW_ARANGO_EXCEPTION_PARAMS(code, ...) \ - throw triagens::arango::Exception(code, triagens::arango::Exception::FillExceptionString(code, __VA_ARGS__), __FILE__, __LINE__) - - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an arango exception with an error code and arbitrary -/// arguments (to be inserted in printf-style manner) -//////////////////////////////////////////////////////////////////////////////// - -#define THROW_ARANGO_EXCEPTION_FORMAT(code, format, ...) \ - throw triagens::arango::Exception(code, \ - triagens::arango::Exception::FillFormatExceptionString( \ - "%s: " format,\ - TRI_errno_string(code), \ - __VA_ARGS__),\ - __FILE__, __LINE__) - -//////////////////////////////////////////////////////////////////////////////// -/// @brief throws an arango exception with an error code and an already-built -/// error message -//////////////////////////////////////////////////////////////////////////////// - -#define THROW_ARANGO_EXCEPTION_MESSAGE(code, message) \ - throw triagens::arango::Exception(code, message, __FILE__, __LINE__) - -// ----------------------------------------------------------------------------- -// --SECTION-- public types -// ----------------------------------------------------------------------------- - -namespace triagens { - namespace arango { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief arango exception type -//////////////////////////////////////////////////////////////////////////////// - - class Exception : public virtual std::exception { - - public: - - Exception (int code, - char const* file, - int line); - - Exception (int code, - std::string const& errorMessage, - char const* file, - int line); - - ~Exception () throw (); - - public: - - char const * what () const throw (); - - std::string message () const throw () { - return _errorMessage; - } - - int code () const throw () { - return _code; - } - - void addToMessage(std::string More) { - _errorMessage += More; - } - - static std::string FillExceptionString (int, ...); - static std::string FillFormatExceptionString (char const * format, - ...); - -//////////////////////////////////////////////////////////////////////////////// -/// @brief controls whether a backtrace is created for each exception -//////////////////////////////////////////////////////////////////////////////// - - static void SetVerbose (bool); - - protected: - std::string _errorMessage; - char const* _file; - int const _line; - int const _code; - }; - - } -} - -#endif - -// ----------------------------------------------------------------------------- -// --SECTION-- END-OF-FILE -// ----------------------------------------------------------------------------- - -// Local Variables: -// mode: outline-minor -// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}" -// End: diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 1b6c660b7c..f0bb948508 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -34,7 +34,7 @@ #include "Cluster/ServerState.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/barrier.h" #include "VocBase/collection.h" #include "VocBase/document-collection.h" @@ -542,7 +542,7 @@ namespace triagens { ! isLocked(trxCollection, TRI_TRANSACTION_WRITE), forceSync); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -648,7 +648,7 @@ namespace triagens { mptr, ! isLocked(trxCollection, TRI_TRANSACTION_READ)); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -1179,7 +1179,7 @@ namespace triagens { forceSync, false); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -1218,7 +1218,7 @@ namespace triagens { ! isLocked(trxCollection, TRI_TRANSACTION_WRITE), forceSync); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { return ex.code(); } catch (...) { @@ -1270,7 +1270,7 @@ namespace triagens { } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/V8Server/v8-collection.cpp b/arangod/V8Server/v8-collection.cpp index 3550e8f500..6840aff61a 100644 --- a/arangod/V8Server/v8-collection.cpp +++ b/arangod/V8Server/v8-collection.cpp @@ -2257,7 +2257,7 @@ static void JS_PropertiesVocbaseCol (const v8::FunctionCallbackInfo& THROW_ARANGO_EXCEPTION(slotInfo.errorCode); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/V8Server/v8-user-structures.cpp b/arangod/V8Server/v8-user-structures.cpp index f0555566a1..4555a61a46 100644 --- a/arangod/V8Server/v8-user-structures.cpp +++ b/arangod/V8Server/v8-user-structures.cpp @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "v8-user-structures.h" +#include "Basics/Exceptions.h" #include "Basics/ReadWriteLock.h" #include "Basics/ReadLocker.h" #include "Basics/WriteLocker.h" @@ -35,7 +36,6 @@ #include "Basics/json.h" #include "Basics/json-utilities.h" #include "Basics/tri-strings.h" -#include "Utils/Exception.h" #include "VocBase/vocbase.h" #include "V8/v8-conv.h" #include "V8/v8-utils.h" diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 9abf35ce2d..395c1428d3 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -582,7 +582,7 @@ static void JS_EnableNativeBacktraces (const v8::FunctionCallbackInfo TRI_V8_THROW_EXCEPTION_USAGE("ENABLE_NATIVE_BACKTRACES()"); } - triagens::arango::Exception::SetVerbose(TRI_ObjectToBoolean(args[0])); + triagens::basics::Exception::SetVerbose(TRI_ObjectToBoolean(args[0])); TRI_V8_RETURN_UNDEFINED(); } diff --git a/arangod/VocBase/document-collection.cpp b/arangod/VocBase/document-collection.cpp index 5edb1cfc21..f86731437c 100644 --- a/arangod/VocBase/document-collection.cpp +++ b/arangod/VocBase/document-collection.cpp @@ -35,6 +35,7 @@ #include "Basics/logging.h" #include "Basics/tri-strings.h" #include "Basics/ThreadPool.h" +#include "Basics/Exceptions.h" #include "CapConstraint/cap-constraint.h" #include "FulltextIndex/fulltext-index.h" #include "GeoIndex/geo-index.h" @@ -44,7 +45,6 @@ #include "Utils/transactions.h" #include "Utils/CollectionReadLocker.h" #include "Utils/CollectionWriteLocker.h" -#include "Utils/Exception.h" #include "VocBase/edge-collection.h" #include "VocBase/index.h" #include "VocBase/key-generator.h" @@ -3505,7 +3505,7 @@ bool TRI_DropIndexDocumentCollection (TRI_document_collection_t* document, return true; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/index.cpp b/arangod/VocBase/index.cpp index 369497f3bb..0ee37b7747 100644 --- a/arangod/VocBase/index.cpp +++ b/arangod/VocBase/index.cpp @@ -39,6 +39,7 @@ #include "Basics/fasthash.h" #include "Basics/json-utilities.h" #include "Basics/JsonHelper.h" +#include "Basics/Exceptions.h" #include "CapConstraint/cap-constraint.h" #include "FulltextIndex/fulltext-index.h" #include "FulltextIndex/fulltext-wordlist.h" @@ -46,7 +47,6 @@ #include "HashIndex/hash-index.h" #include "ShapedJson/shape-accessor.h" #include "ShapedJson/shaped-json.h" -#include "Utils/Exception.h" #include "VocBase/document-collection.h" #include "VocBase/edge-collection.h" #include "VocBase/server.h" @@ -386,7 +386,7 @@ int TRI_SaveIndex (TRI_document_collection_t* document, TRI_FreeJson(TRI_CORE_MEM_ZONE, json); return TRI_ERROR_NO_ERROR; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/replication-dump.cpp b/arangod/VocBase/replication-dump.cpp index dfaff341f7..9b3074b219 100644 --- a/arangod/VocBase/replication-dump.cpp +++ b/arangod/VocBase/replication-dump.cpp @@ -1442,7 +1442,7 @@ int TRI_DumpLogReplication (TRI_replication_dump_t* dump, } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/replication-dump.h b/arangod/VocBase/replication-dump.h index 689ae4ffab..3fdfd0a9d6 100644 --- a/arangod/VocBase/replication-dump.h +++ b/arangod/VocBase/replication-dump.h @@ -34,8 +34,8 @@ #include "Basics/associative.h" #include "Basics/string-buffer.h" +#include "Basics/Exceptions.h" #include "ShapedJson/shaped-json.h" -#include "Utils/Exception.h" #include "VocBase/replication-common.h" #include "VocBase/voc-types.h" #include "VocBase/vocbase.h" diff --git a/arangod/VocBase/server.cpp b/arangod/VocBase/server.cpp index 73f2e6e8c4..bf784a2134 100644 --- a/arangod/VocBase/server.cpp +++ b/arangod/VocBase/server.cpp @@ -46,7 +46,7 @@ #include "Basics/random.h" #include "Basics/tri-strings.h" #include "Basics/JsonHelper.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/auth.h" #include "VocBase/replication-applier.h" #include "VocBase/vocbase.h" @@ -1503,7 +1503,7 @@ static int WriteCreateMarker (TRI_voc_tick_t id, THROW_ARANGO_EXCEPTION(slotInfo.errorCode); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -1533,7 +1533,7 @@ static int WriteDropMarker (TRI_voc_tick_t id) { THROW_ARANGO_EXCEPTION(slotInfo.errorCode); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/transaction.cpp b/arangod/VocBase/transaction.cpp index e428eada04..20d4a30ff1 100644 --- a/arangod/VocBase/transaction.cpp +++ b/arangod/VocBase/transaction.cpp @@ -32,8 +32,7 @@ #include "Basics/conversions.h" #include "Basics/logging.h" #include "Basics/tri-strings.h" - -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/collection.h" #include "VocBase/document-collection.h" #include "VocBase/server.h" @@ -648,7 +647,7 @@ static int WriteBeginMarker (TRI_transaction_t* trx) { trx->_beginWritten = true; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -695,7 +694,7 @@ static int WriteAbortMarker (TRI_transaction_t* trx) { res = GetLogfileManager()->allocateAndWrite(marker, false).errorCode; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -738,7 +737,7 @@ static int WriteCommitMarker (TRI_transaction_t* trx) { res = GetLogfileManager()->allocateAndWrite(marker, false).errorCode; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/voc-shaper.cpp b/arangod/VocBase/voc-shaper.cpp index 3b3c5e939e..7341566d01 100644 --- a/arangod/VocBase/voc-shaper.cpp +++ b/arangod/VocBase/voc-shaper.cpp @@ -41,7 +41,7 @@ #include "Basics/logging.h" #include "Basics/tri-strings.h" #include "Basics/utf8-helper.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/document-collection.h" #include "Wal/LogfileManager.h" @@ -218,7 +218,7 @@ static TRI_shape_aid_t FindOrCreateAttributeByName (TRI_shaper_t* shaper, return aid; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -387,7 +387,7 @@ static TRI_shape_t const* FindShape (TRI_shaper_t* shaper, TRI_Free(TRI_UNKNOWN_MEM_ZONE, shape); return result; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/VocBase/vocbase.cpp b/arangod/VocBase/vocbase.cpp index 602e6afef3..fe5513d3b1 100644 --- a/arangod/VocBase/vocbase.cpp +++ b/arangod/VocBase/vocbase.cpp @@ -45,8 +45,7 @@ #include "Basics/random.h" #include "Basics/tri-strings.h" #include "Basics/threads.h" - -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "Utils/transactions.h" #include "VocBase/auth.h" #include "VocBase/barrier.h" @@ -182,7 +181,7 @@ static int WriteDropCollectionMarker (TRI_vocbase_t* vocbase, THROW_ARANGO_EXCEPTION(slotInfo.errorCode); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -682,7 +681,7 @@ static TRI_vocbase_col_t* CreateCollection (TRI_vocbase_t* vocbase, TRI_FreeJson(TRI_CORE_MEM_ZONE, json); return collection; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -833,7 +832,7 @@ static int RenameCollection (TRI_vocbase_t* vocbase, return TRI_ERROR_NO_ERROR; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/Wal/AllocatorThread.cpp b/arangod/Wal/AllocatorThread.cpp index 16c608e33a..b12a736ffd 100644 --- a/arangod/Wal/AllocatorThread.cpp +++ b/arangod/Wal/AllocatorThread.cpp @@ -30,7 +30,7 @@ #include "AllocatorThread.h" #include "Basics/logging.h" #include "Basics/ConditionLocker.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "Wal/LogfileManager.h" using namespace triagens::wal; @@ -157,7 +157,7 @@ void AllocatorThread::run () { LOG_ERROR("unable to create new WAL reserve logfile"); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { int res = ex.code(); LOG_ERROR("got unexpected error in allocatorThread: %s", TRI_errno_string(res)); } diff --git a/arangod/Wal/CollectorThread.cpp b/arangod/Wal/CollectorThread.cpp index 9b5263265d..5bb5869b46 100644 --- a/arangod/Wal/CollectorThread.cpp +++ b/arangod/Wal/CollectorThread.cpp @@ -28,13 +28,14 @@ //////////////////////////////////////////////////////////////////////////////// #include "CollectorThread.h" + #include "Basics/MutexLocker.h" #include "Basics/hashes.h" #include "Basics/logging.h" #include "Basics/ConditionLocker.h" +#include "Basics/Exceptions.h" #include "Utils/CollectionGuard.h" #include "Utils/DatabaseGuard.h" -#include "Utils/Exception.h" #include "Utils/transactions.h" #include "VocBase/document-collection.h" #include "VocBase/server.h" @@ -365,7 +366,7 @@ void CollectorThread::run () { throw; } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { int res = ex.code(); LOG_ERROR("got unexpected error in collectorThread::run: %s", TRI_errno_string(res)); } @@ -468,7 +469,7 @@ bool CollectorThread::processQueuedOperations () { try { res = processCollectionOperations((*it2)); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } @@ -704,7 +705,7 @@ int CollectorThread::processCollectionOperations (CollectorCache* cache) { res = TRI_ERROR_NO_ERROR; } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -807,7 +808,7 @@ int CollectorThread::collect (Logfile* logfile) { try { res = transferMarkers(logfile, cid, state.collections[cid], state.operationsCount[cid], sortedOperations); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -886,7 +887,7 @@ int CollectorThread::transferMarkers (Logfile* logfile, queueOperations(logfile, cache); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/Wal/LogfileManager.cpp b/arangod/Wal/LogfileManager.cpp index f90165ce07..73af4a1b29 100644 --- a/arangod/Wal/LogfileManager.cpp +++ b/arangod/Wal/LogfileManager.cpp @@ -38,7 +38,6 @@ #include "Basics/ReadLocker.h" #include "Basics/StringUtils.h" #include "Basics/WriteLocker.h" -#include "Utils/Exception.h" #include "VocBase/server.h" #include "Wal/AllocatorThread.h" #include "Wal/CollectorThread.h" diff --git a/arangod/Wal/RecoverState.cpp b/arangod/Wal/RecoverState.cpp index c3214a96c9..b176ca8231 100644 --- a/arangod/Wal/RecoverState.cpp +++ b/arangod/Wal/RecoverState.cpp @@ -31,12 +31,12 @@ #include "Basics/FileUtils.h" #include "Basics/conversions.h" #include "Basics/files.h" +#include "Basics/Exceptions.h" #include "VocBase/collection.h" #include "VocBase/replication-applier.h" #include "VocBase/voc-shaper.h" #include "Wal/LogfileManager.h" #include "Wal/Slots.h" -#include "Utils/Exception.h" using namespace triagens::wal; @@ -452,7 +452,7 @@ int RecoverState::executeRemoteOperation (TRI_voc_tick_t databaseId, THROW_ARANGO_EXCEPTION(res); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -536,7 +536,7 @@ int RecoverState::executeSingleOperation (TRI_voc_tick_t databaseId, // commit the operation res = trx->commit(); } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { @@ -1620,7 +1620,7 @@ int RecoverState::abortOpenTransactions () { } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { res = ex.code(); } catch (...) { diff --git a/arangod/Wal/RemoverThread.cpp b/arangod/Wal/RemoverThread.cpp index cc95a386bb..ee3a434b46 100644 --- a/arangod/Wal/RemoverThread.cpp +++ b/arangod/Wal/RemoverThread.cpp @@ -28,9 +28,10 @@ //////////////////////////////////////////////////////////////////////////////// #include "RemoverThread.h" + #include "Basics/logging.h" #include "Basics/ConditionLocker.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "Wal/LogfileManager.h" using namespace triagens::wal; @@ -108,7 +109,7 @@ void RemoverThread::run () { worked = _logfileManager->removeLogfiles(); } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { int res = ex.code(); LOG_ERROR("got unexpected error in removerThread::run: %s", TRI_errno_string(res)); } diff --git a/arangod/Wal/SynchroniserThread.cpp b/arangod/Wal/SynchroniserThread.cpp index 4ec4966f5c..8123e31175 100644 --- a/arangod/Wal/SynchroniserThread.cpp +++ b/arangod/Wal/SynchroniserThread.cpp @@ -28,9 +28,10 @@ //////////////////////////////////////////////////////////////////////////////// #include "SynchroniserThread.h" + #include "Basics/logging.h" #include "Basics/ConditionLocker.h" -#include "Utils/Exception.h" +#include "Basics/Exceptions.h" #include "VocBase/server.h" #include "Wal/LogfileManager.h" #include "Wal/Slots.h" @@ -137,7 +138,7 @@ void SynchroniserThread::run () { } } } - catch (triagens::arango::Exception const& ex) { + catch (triagens::basics::Exception const& ex) { int res = ex.code(); LOG_ERROR("got unexpected error in synchroniserThread: %s", TRI_errno_string(res)); } diff --git a/lib/Admin/RestBaseHandler.cpp b/lib/Admin/RestBaseHandler.cpp index 6fdd4d5a13..d8295a5296 100644 --- a/lib/Admin/RestBaseHandler.cpp +++ b/lib/Admin/RestBaseHandler.cpp @@ -53,15 +53,29 @@ RestBaseHandler::RestBaseHandler (HttpRequest* request) } // ----------------------------------------------------------------------------- -// --SECTION-- HttpHandler methods +// --SECTION-- Handler methods // ----------------------------------------------------------------------------- -void RestBaseHandler::handleError (TriagensError const& error) { +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + +void RestBaseHandler::handleError (const TriagensError& error) { generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL, DIAGNOSTIC_INFORMATION(error)); } +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + +void RestBaseHandler::handleError (const Exception& error) { + generateError(HttpResponse::responseCode(error.code()), + error.code(), + DIAGNOSTIC_INFORMATION(error)); +} + // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- diff --git a/lib/Admin/RestBaseHandler.h b/lib/Admin/RestBaseHandler.h index 477ae473e6..907f3262a8 100644 --- a/lib/Admin/RestBaseHandler.h +++ b/lib/Admin/RestBaseHandler.h @@ -63,7 +63,7 @@ namespace triagens { RestBaseHandler (rest::HttpRequest* request); // ----------------------------------------------------------------------------- -// --SECTION-- HttpHandler methods +// --SECTION-- Handler methods // ----------------------------------------------------------------------------- public: @@ -74,6 +74,12 @@ namespace triagens { void handleError (basics::TriagensError const&); +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + + void handleError (basics::Exception const&); + // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- diff --git a/lib/Basics/Exceptions.cpp b/lib/Basics/Exceptions.cpp index 8f9f791156..30f55728e5 100644 --- a/lib/Basics/Exceptions.cpp +++ b/lib/Basics/Exceptions.cpp @@ -32,10 +32,24 @@ using namespace std; using namespace triagens::basics; +// ----------------------------------------------------------------------------- +// --SECTION-- private variables +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief controls if backtraces are printed with exceptions +//////////////////////////////////////////////////////////////////////////////// + +static bool WithBackTrace = false; + // ----------------------------------------------------------------------------- // --SECTION-- public types // ----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- +// --SECTION-- class TriagensError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief base class for all errors //////////////////////////////////////////////////////////////////////////////// @@ -57,20 +71,27 @@ TriagensError::TriagensError (string const& type, string const& details, char co TRI_GetBacktrace(_message); #endif #endif - } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// TriagensError::~TriagensError () throw () { } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the error messages +//////////////////////////////////////////////////////////////////////////////// char const * TriagensError::what () const throw() { return _message.c_str(); } +// ----------------------------------------------------------------------------- +// --SECTION-- class InternalError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for internal errors //////////////////////////////////////////////////////////////////////////////// @@ -79,12 +100,25 @@ InternalError::InternalError (string const& details, char const* file, int line) : TriagensError("internal error", details, file, line) { } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief exception for internal errors +//////////////////////////////////////////////////////////////////////////////// InternalError::InternalError (std::exception const& ex, char const* file, int line) : TriagensError("internal exception", ex.what(), file, line) { } +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// + +InternalError::~InternalError () throw () { +} + +// ----------------------------------------------------------------------------- +// --SECTION-- class OutOfMemoryError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for out-of-memory errors //////////////////////////////////////////////////////////////////////////////// @@ -93,6 +127,17 @@ OutOfMemoryError::OutOfMemoryError (char const* file, int line) : TriagensError("out-of-memory", "", file, line) { } +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// + +OutOfMemoryError::~OutOfMemoryError () throw () { +} + +// ----------------------------------------------------------------------------- +// --SECTION-- class FileError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for file errors //////////////////////////////////////////////////////////////////////////////// @@ -122,12 +167,16 @@ FileError::FileError (string const& func, } } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// FileError::~FileError () throw () { } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets the filename +//////////////////////////////////////////////////////////////////////////////// void FileError::setFilename (string const& filename) { _filename = filename; @@ -137,6 +186,10 @@ void FileError::setFilename (string const& filename) { } } +// ----------------------------------------------------------------------------- +// --SECTION-- class ParseError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parse errors //////////////////////////////////////////////////////////////////////////////// @@ -152,7 +205,16 @@ ParseError::ParseError (string const& details, } } +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// +ParseError::~ParseError () throw () { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sets the line number +//////////////////////////////////////////////////////////////////////////////// void ParseError::setLineNumber (int lineNumber) { _lineNumber = lineNumber; @@ -162,6 +224,10 @@ void ParseError::setLineNumber (int lineNumber) { } } +// ----------------------------------------------------------------------------- +// --SECTION-- class ParameterError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parameter errors //////////////////////////////////////////////////////////////////////////////// @@ -181,11 +247,160 @@ ParameterError::ParameterError (string const& parameter, } } - +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// ParameterError::~ParameterError () throw () { } +// ----------------------------------------------------------------------------- +// --SECTION-- class Exception +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief controls whether a backtrace is created for each exception +//////////////////////////////////////////////////////////////////////////////// + +void Exception::SetVerbose (bool verbose) { + WithBackTrace = verbose; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructor, without format string +//////////////////////////////////////////////////////////////////////////////// + +Exception::Exception (int code, + char const* file, + int line) + : _errorMessage(TRI_errno_string(code)), + _file(file), + _line(line), + _code(code) { + +#ifdef TRI_ENABLE_MAINTAINER_MODE +#if HAVE_BACKTRACE + if (WithBackTrace) { + _errorMessage += std::string("\n\n"); + TRI_GetBacktrace(_errorMessage); + _errorMessage += std::string("\n\n"); + } +#endif +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the error message +//////////////////////////////////////////////////////////////////////////////// + +string Exception::message () const throw () { + return _errorMessage; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the error code +//////////////////////////////////////////////////////////////////////////////// + +int Exception::code () const throw () { + return _code; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief adds to the message +//////////////////////////////////////////////////////////////////////////////// + +void Exception::addToMessage (string More) { + _errorMessage += More; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief constructor, for creating an exception with an already created +/// error message (normally based on error templates containing %s, %d etc.) +//////////////////////////////////////////////////////////////////////////////// + +Exception::Exception (int code, + string const& errorMessage, + char const* file, + int line) + : _errorMessage(errorMessage), + _file(file), + _line(line), + _code(code) { + +#ifdef TRI_ENABLE_MAINTAINER_MODE +#if HAVE_BACKTRACE + if (WithBackTrace) { + _errorMessage += std::string("\n\n"); + TRI_GetBacktrace(_errorMessage); + _errorMessage += std::string("\n\n"); + } +#endif +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief destructor +//////////////////////////////////////////////////////////////////////////////// + +Exception::~Exception () throw () { +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief return exception message +//////////////////////////////////////////////////////////////////////////////// + +const char* Exception::what () const throw () { + return _errorMessage.c_str(); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief construct an error message from a template string +//////////////////////////////////////////////////////////////////////////////// + +std::string Exception::FillExceptionString (int code, ...) { + char const* format = TRI_errno_string(code); + TRI_ASSERT(format != nullptr); + +#ifdef TRI_ENABLE_MAINTAINER_MODE + // Obviously the formatstring of the error code has to support parameters. + TRI_ASSERT(strchr(format, '%') != nullptr); +#endif + + char buffer[1024]; + va_list ap; + va_start(ap, code); + vsnprintf(buffer, sizeof(buffer) - 1, format, ap); + va_end(ap); + buffer[sizeof(buffer) - 1] = '\0'; // Windows + + return std::string(buffer); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief construct an error message from a template string +//////////////////////////////////////////////////////////////////////////////// + +std::string Exception::FillFormatExceptionString (char const* format, ...) { + TRI_ASSERT(format != nullptr); + +#ifdef TRI_ENABLE_MAINTAINER_MODE + // Format #1 should come from the macro... + TRI_ASSERT(strchr(format, '%') != nullptr); + // Obviously the user has to give us a format string. + TRI_ASSERT(strchr(strchr(format, '%'), '%') != nullptr); +#endif + + char buffer[1024]; + va_list ap; + va_start(ap, format); + vsnprintf(buffer, sizeof(buffer) - 1, format, ap); + va_end(ap); + buffer[sizeof(buffer) - 1] = '\0'; // Windows + + return std::string(buffer); +} + + // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- diff --git a/lib/Basics/Exceptions.h b/lib/Basics/Exceptions.h index 46f21e912d..841f3a19e7 100644 --- a/lib/Basics/Exceptions.h +++ b/lib/Basics/Exceptions.h @@ -5,7 +5,7 @@ /// /// DISCLAIMER /// -/// Copyright 2014 ArangoDB GmbH, Cologne, Germany +/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,8 @@ /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Dr. Frank Celler -/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany +/// @author Jan Steemann +/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany /// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// @@ -130,6 +131,48 @@ #define THROW_PARAMETER_ERROR(parameter, details, func) \ throw triagens::basics::ParameterError(parameter, details, func, __FILE__, __LINE__) +//////////////////////////////////////////////////////////////////////////////// +/// @brief throws an arango exception with an error code +//////////////////////////////////////////////////////////////////////////////// + +#define THROW_ARANGO_EXCEPTION(code) \ + throw triagens::basics::Exception(code, __FILE__, __LINE__) + +//////////////////////////////////////////////////////////////////////////////// +/// @brief throws an arango exception with an error code and arbitrary +/// arguments (to be inserted in printf-style manner) +//////////////////////////////////////////////////////////////////////////////// + +#define THROW_ARANGO_EXCEPTION_PARAMS(code, ...) \ + throw triagens::basics::Exception( \ + code, \ + triagens::basics::Exception::FillExceptionString( \ + code, \ + __VA_ARGS__), \ + __FILE__, __LINE__) + +//////////////////////////////////////////////////////////////////////////////// +/// @brief throws an arango exception with an error code and arbitrary +/// arguments (to be inserted in printf-style manner) +//////////////////////////////////////////////////////////////////////////////// + +#define THROW_ARANGO_EXCEPTION_FORMAT(code, format, ...) \ + throw triagens::basics::Exception( \ + code, \ + triagens::basics::Exception::FillFormatExceptionString( \ + "%s: " format, \ + TRI_errno_string(code), \ + __VA_ARGS__), \ + __FILE__, __LINE__) + +//////////////////////////////////////////////////////////////////////////////// +/// @brief throws an arango exception with an error code and an already-built +/// error message +//////////////////////////////////////////////////////////////////////////////// + +#define THROW_ARANGO_EXCEPTION_MESSAGE(code, message) \ + throw triagens::basics::Exception(code, message, __FILE__, __LINE__) + // ----------------------------------------------------------------------------- // --SECTION-- public types // ----------------------------------------------------------------------------- @@ -137,6 +180,10 @@ namespace triagens { namespace basics { +// ----------------------------------------------------------------------------- +// --SECTION-- class TriagensError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief base class for all errors //////////////////////////////////////////////////////////////////////////////// @@ -161,6 +208,10 @@ namespace triagens { int _line; }; +// ----------------------------------------------------------------------------- +// --SECTION-- class InternalError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for internal errors //////////////////////////////////////////////////////////////////////////////// @@ -169,8 +220,14 @@ namespace triagens { public: InternalError (std::string const& details, char const* file, int line); InternalError (std::exception const& ex, char const* file, int line); + + ~InternalError () throw (); }; +// ----------------------------------------------------------------------------- +// --SECTION-- class OutOfMemoryError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for out-of-memory errors //////////////////////////////////////////////////////////////////////////////// @@ -178,8 +235,14 @@ namespace triagens { class OutOfMemoryError : public TriagensError { public: OutOfMemoryError (char const* file, int line); + + ~OutOfMemoryError () throw (); }; +// ----------------------------------------------------------------------------- +// --SECTION-- class FileError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for file errors //////////////////////////////////////////////////////////////////////////////// @@ -206,6 +269,10 @@ namespace triagens { int _error; }; +// ----------------------------------------------------------------------------- +// --SECTION-- class ParseError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parse errors //////////////////////////////////////////////////////////////////////////////// @@ -217,6 +284,8 @@ namespace triagens { char const* file, int line); + ~ParseError () throw (); + public: void setLineNumber (int); @@ -224,6 +293,10 @@ namespace triagens { int _lineNumber; }; +// ----------------------------------------------------------------------------- +// --SECTION-- class ParameterError +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @brief exception for parameter errors //////////////////////////////////////////////////////////////////////////////// @@ -242,6 +315,45 @@ namespace triagens { std::string _parameter; std::string _func; }; + +// ----------------------------------------------------------------------------- +// --SECTION-- class Exception +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief arango exception type +//////////////////////////////////////////////////////////////////////////////// + + class Exception : public virtual std::exception { + public: + static std::string FillExceptionString (int, ...); + static std::string FillFormatExceptionString (char const * format, ...); + static void SetVerbose (bool); + + public: + Exception (int code, + char const* file, + int line); + + Exception (int code, + std::string const& errorMessage, + char const* file, + int line); + + ~Exception () throw (); + + public: + char const * what () const throw (); + std::string message () const throw (); + int code () const throw (); + void addToMessage (std::string More); + + protected: + std::string _errorMessage; + char const* _file; + int const _line; + int const _code; + }; } } diff --git a/lib/Basics/JsonHelper.cpp b/lib/Basics/JsonHelper.cpp index 1fedfd6e4f..b8fe1a1d6f 100644 --- a/lib/Basics/JsonHelper.cpp +++ b/lib/Basics/JsonHelper.cpp @@ -297,7 +297,7 @@ bool JsonHelper::checkAndGetBooleanValue (TRI_json_t const* json, if (! isBoolean(sub)) { std::string msg = "The attribute '" + std::string(name) + "' was not found or is not a boolean."; - THROW_INTERNAL_ERROR(msg); + THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg); } return sub->_value._boolean; @@ -315,7 +315,7 @@ std::string JsonHelper::checkAndGetStringValue (TRI_json_t const* json, if (! isString(sub)) { std::string msg = "The attribute '" + std::string(name) + "' was not found or is not a string."; - THROW_INTERNAL_ERROR(msg); + THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg); } return string(sub->_value._string.data, sub->_value._string.length - 1); } @@ -332,7 +332,7 @@ TRI_json_t const* JsonHelper::checkAndGetObjectValue (TRI_json_t const* json, if (! isObject(sub)) { std::string msg = "The attribute '" + std::string(name) + "' was not found or is not an object."; - THROW_INTERNAL_ERROR(msg); + THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg); } return sub; @@ -350,7 +350,7 @@ TRI_json_t const* JsonHelper::checkAndGetArrayValue (TRI_json_t const* json, if (! isArray(sub)) { std::string msg = "The attribute '" + std::string(name) + "' was not found or is not an array."; - THROW_INTERNAL_ERROR(msg); + THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, msg); } return sub; diff --git a/lib/HttpServer/HttpHandlerFactory.cpp b/lib/HttpServer/HttpHandlerFactory.cpp index 770ce7595f..ed4b9ddf0f 100644 --- a/lib/HttpServer/HttpHandlerFactory.cpp +++ b/lib/HttpServer/HttpHandlerFactory.cpp @@ -72,7 +72,11 @@ namespace { return status_t(HANDLER_DONE); }; - void handleError (TriagensError const& error) { + void handleError (const TriagensError& error) { + _response = createResponse(HttpResponse::SERVICE_UNAVAILABLE); + }; + + void handleError (const Exception& error) { _response = createResponse(HttpResponse::SERVICE_UNAVAILABLE); }; }; diff --git a/lib/HttpServer/PathHandler.cpp b/lib/HttpServer/PathHandler.cpp index c48a3d6874..f718d8dd1d 100644 --- a/lib/HttpServer/PathHandler.cpp +++ b/lib/HttpServer/PathHandler.cpp @@ -204,7 +204,11 @@ namespace triagens { - void PathHandler::handleError (TriagensError const&) { + void PathHandler::handleError (const TriagensError&) { + _response = createResponse(HttpResponse::SERVER_ERROR); + } + + void PathHandler::handleError (const Exception&) { _response = createResponse(HttpResponse::SERVER_ERROR); } } diff --git a/lib/HttpServer/PathHandler.h b/lib/HttpServer/PathHandler.h index c8b4b92271..d86783e018 100644 --- a/lib/HttpServer/PathHandler.h +++ b/lib/HttpServer/PathHandler.h @@ -108,7 +108,13 @@ namespace triagens { /// {@inheritDoc} //////////////////////////////////////////////////////////////////////////////// - void handleError (basics::TriagensError const&); + void handleError (const basics::TriagensError&); + +//////////////////////////////////////////////////////////////////////////////// +/// {@inheritDoc} +//////////////////////////////////////////////////////////////////////////////// + + void handleError (const basics::Exception&); private: std::string path; diff --git a/lib/Rest/Handler.h b/lib/Rest/Handler.h index 7c44eec609..edfea984d1 100644 --- a/lib/Rest/Handler.h +++ b/lib/Rest/Handler.h @@ -187,7 +187,13 @@ namespace triagens { /// @brief handles error //////////////////////////////////////////////////////////////////////////////// - virtual void handleError (basics::TriagensError const&) = 0; + virtual void handleError (const basics::TriagensError&) = 0; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief handles error +//////////////////////////////////////////////////////////////////////////////// + + virtual void handleError (const basics::Exception&) = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief creates a job diff --git a/lib/Rest/HttpResponse.cpp b/lib/Rest/HttpResponse.cpp index 2fa240dcab..0ea8efee19 100644 --- a/lib/Rest/HttpResponse.cpp +++ b/lib/Rest/HttpResponse.cpp @@ -190,6 +190,53 @@ HttpResponse::HttpResponseCode HttpResponse::responseCode (const string& str) { } } +//////////////////////////////////////////////////////////////////////////////// +/// @brief get http response code from integer error code +//////////////////////////////////////////////////////////////////////////////// + +HttpResponse::HttpResponseCode HttpResponse::responseCode (int code) { + TRI_ASSERT(code != TRI_ERROR_NO_ERROR); + + switch (code) { + case TRI_ERROR_ARANGO_DOCUMENT_KEY_BAD: + case TRI_ERROR_ARANGO_DOCUMENT_KEY_UNEXPECTED: + case TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID: + case TRI_ERROR_BAD_PARAMETER: + case TRI_ERROR_CLUSTER_MUST_NOT_CHANGE_SHARDING_ATTRIBUTES: + case TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY: + return BAD; + + case TRI_ERROR_ARANGO_READ_ONLY: + return FORBIDDEN; + + case TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND: + case TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND: + return NOT_FOUND; + + case TRI_ERROR_REQUEST_CANCELED: + case TRI_ERROR_QUERY_KILLED: + return REQUEST_TIMEOUT; + + case TRI_ERROR_ARANGO_CONFLICT: + case TRI_ERROR_ARANGO_GEO_INDEX_VIOLATED: + case TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED: + return CONFLICT; + + case TRI_ERROR_ARANGO_OUT_OF_KEYS: + case TRI_ERROR_CLUSTER_SHARD_GONE: + case TRI_ERROR_CLUSTER_TIMEOUT: + return SERVER_ERROR; + + case TRI_ERROR_CLUSTER_UNSUPPORTED: + return NOT_IMPLEMENTED; + + case TRI_ERROR_OUT_OF_MEMORY: + case TRI_ERROR_INTERNAL: + default: + return SERVER_ERROR; + } +} + //////////////////////////////////////////////////////////////////////////////// /// @brief return the batch error count header //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Rest/HttpResponse.h b/lib/Rest/HttpResponse.h index ab35758c41..14392d6084 100644 --- a/lib/Rest/HttpResponse.h +++ b/lib/Rest/HttpResponse.h @@ -150,6 +150,12 @@ namespace triagens { static HttpResponseCode responseCode (std::string const& str); +//////////////////////////////////////////////////////////////////////////////// +/// @brief get http response code from integer error code +//////////////////////////////////////////////////////////////////////////////// + + static HttpResponseCode responseCode (int); + //////////////////////////////////////////////////////////////////////////////// /// @brief return the batch response error count header ////////////////////////////////////////////////////////////////////////////////