1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
Jan Steemann 2012-09-13 17:41:21 +02:00
commit 967716a27b
13 changed files with 358 additions and 672 deletions

View File

@ -328,10 +328,10 @@ am__v_at_0 = @
lib_libarango_a_AR = $(AR) $(ARFLAGS)
lib_libarango_a_LIBADD =
am__lib_libarango_a_SOURCES_DIST = lib/Basics/ConditionLocker.cpp \
lib/Basics/ConditionVariable.cpp lib/Basics/FileUtils.cpp \
lib/Basics/Initialise.cpp lib/Basics/LibraryLoader.cpp \
lib/Basics/Mutex.cpp lib/Basics/MutexLocker.cpp \
lib/Basics/ProgramOptions.cpp \
lib/Basics/ConditionVariable.cpp lib/Basics/Exceptions.cpp \
lib/Basics/FileUtils.cpp lib/Basics/Initialise.cpp \
lib/Basics/LibraryLoader.cpp lib/Basics/Mutex.cpp \
lib/Basics/MutexLocker.cpp lib/Basics/ProgramOptions.cpp \
lib/Basics/ProgramOptionsDescription.cpp lib/Basics/Random.cpp \
lib/Basics/ReadLocker.cpp lib/Basics/ReadUnlocker.cpp \
lib/Basics/ReadWriteLock.cpp lib/Basics/StringUtils.cpp \
@ -387,7 +387,8 @@ am__dirstamp = $(am__leading_dot)dirstamp
@ENABLE_ZEROMQ_TRUE@ lib/ZeroMQ/ZeroMQWorkerThread.$(OBJEXT)
am_lib_libarango_a_OBJECTS = lib/Basics/ConditionLocker.$(OBJEXT) \
lib/Basics/ConditionVariable.$(OBJEXT) \
lib/Basics/FileUtils.$(OBJEXT) lib/Basics/Initialise.$(OBJEXT) \
lib/Basics/Exceptions.$(OBJEXT) lib/Basics/FileUtils.$(OBJEXT) \
lib/Basics/Initialise.$(OBJEXT) \
lib/Basics/LibraryLoader.$(OBJEXT) lib/Basics/Mutex.$(OBJEXT) \
lib/Basics/MutexLocker.$(OBJEXT) \
lib/Basics/ProgramOptions.$(OBJEXT) \
@ -1250,10 +1251,10 @@ WIKI = \
jsUnity
lib_libarango_a_SOURCES = lib/Basics/ConditionLocker.cpp \
lib/Basics/ConditionVariable.cpp lib/Basics/FileUtils.cpp \
lib/Basics/Initialise.cpp lib/Basics/LibraryLoader.cpp \
lib/Basics/Mutex.cpp lib/Basics/MutexLocker.cpp \
lib/Basics/ProgramOptions.cpp \
lib/Basics/ConditionVariable.cpp lib/Basics/Exceptions.cpp \
lib/Basics/FileUtils.cpp lib/Basics/Initialise.cpp \
lib/Basics/LibraryLoader.cpp lib/Basics/Mutex.cpp \
lib/Basics/MutexLocker.cpp lib/Basics/ProgramOptions.cpp \
lib/Basics/ProgramOptionsDescription.cpp lib/Basics/Random.cpp \
lib/Basics/ReadLocker.cpp lib/Basics/ReadUnlocker.cpp \
lib/Basics/ReadWriteLock.cpp lib/Basics/StringUtils.cpp \
@ -1745,6 +1746,8 @@ lib/Basics/ConditionLocker.$(OBJEXT): lib/Basics/$(am__dirstamp) \
lib/Basics/$(DEPDIR)/$(am__dirstamp)
lib/Basics/ConditionVariable.$(OBJEXT): lib/Basics/$(am__dirstamp) \
lib/Basics/$(DEPDIR)/$(am__dirstamp)
lib/Basics/Exceptions.$(OBJEXT): lib/Basics/$(am__dirstamp) \
lib/Basics/$(DEPDIR)/$(am__dirstamp)
lib/Basics/FileUtils.$(OBJEXT): lib/Basics/$(am__dirstamp) \
lib/Basics/$(DEPDIR)/$(am__dirstamp)
lib/Basics/Initialise.$(OBJEXT): lib/Basics/$(am__dirstamp) \
@ -2840,6 +2843,7 @@ mostlyclean-compile:
-rm -f lib/ApplicationServer/ApplicationServer.$(OBJEXT)
-rm -f lib/Basics/ConditionLocker.$(OBJEXT)
-rm -f lib/Basics/ConditionVariable.$(OBJEXT)
-rm -f lib/Basics/Exceptions.$(OBJEXT)
-rm -f lib/Basics/FileUtils.$(OBJEXT)
-rm -f lib/Basics/Initialise.$(OBJEXT)
-rm -f lib/Basics/LibraryLoader.$(OBJEXT)
@ -3092,6 +3096,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@lib/ApplicationServer/$(DEPDIR)/ApplicationServer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/ConditionLocker.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/ConditionVariable.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/Exceptions.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/FileUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/Initialise.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@lib/Basics/$(DEPDIR)/LibraryLoader.Po@am__quote@

View File

@ -140,12 +140,12 @@ namespace triagens {
handler->handleError(ex);
}
catch (std::exception const& ex) {
triagens::basics::InternalError err(ex);
triagens::basics::InternalError err(ex, __FILE__, __LINE__);
handler->handleError(err);
}
catch (...) {
triagens::basics::InternalError err;
triagens::basics::InternalError err("executeDirectHandler", __FILE__, __LINE__);
handler->handleError(err);
}
}

View File

@ -42,6 +42,7 @@
#include "Basics/StringUtils.h"
#include "BasicsC/json.h"
#include "BasicsC/strings.h"
#include "SimpleHttpClient/GeneralClientConnection.h"
#include "SimpleHttpClient/SimpleHttpClient.h"
#include "SimpleHttpClient/SimpleHttpResult.h"
@ -108,21 +109,39 @@ MRubyClientConnection::MRubyClientConnection (MR_state_t* mrs,
_lastHttpReturnCode = result->getHttpReturnCode();
if (result->getHttpReturnCode() == SimpleHttpResult::HTTP_STATUS_OK) {
triagens::basics::VariantArray* json = result->getBodyAsVariantArray();
// default value
_version = "arango";
// convert response body to json
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, result->getBody().str().c_str());
if (json) {
triagens::basics::VariantString* vs = json->lookupString("server");
if (vs && vs->getValue() == "arango") {
// connected to arango server
vs = json->lookupString("version");
// look up "server" value (this returns a pointer, not a copy)
TRI_json_t* server = TRI_LookupArrayJson(json, "server");
if (vs) {
_version = vs->getValue();
if (server) {
// "server" value is a string and content is "arango"
if (server->_type == TRI_JSON_STRING && TRI_EqualString(server->_value._string.data, "arango")) {
// look up "version" value (this returns a pointer, not a copy)
TRI_json_t* vs = TRI_LookupArrayJson(json, "version");
if (vs) {
// "version" value is a string
if (vs->_type == TRI_JSON_STRING) {
_version = string(vs->_value._string.data, vs->_value._string.length);
}
}
}
// must not free server and vs, they are contained in the "json" variable and freed below
}
delete json;
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
}
}
}

View File

@ -101,27 +101,35 @@ V8ClientConnection::V8ClientConnection (Endpoint* endpoint,
_lastHttpReturnCode = result->getHttpReturnCode();
if (result->getHttpReturnCode() == SimpleHttpResult::HTTP_STATUS_OK) {
// default value
_version = "arango";
// convert response body to json
TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, result->getBody().str().c_str());
if (json) {
// look up "server" value (this returns a pointer, not a copy)
TRI_json_t* server = TRI_LookupArrayJson(json, "server");
if (server) {
// "server" value is a string and content is "arango"
if (server->_type == TRI_JSON_STRING && TRI_EqualString(server->_value._string.data, "arango")) {
// look up "version" value (this returns a pointer, not a copy)
TRI_json_t* vs = TRI_LookupArrayJson(json, "version");
if (vs) {
// "version" value is a string
if (vs->_type == TRI_JSON_STRING) {
_version = string(vs->_value._string.data, vs->_value._string.length);
}
}
}
// must not free server and vs, they are contained in the "json" variable and freed below
}

196
lib/Basics/Exceptions.cpp Normal file
View File

@ -0,0 +1,196 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief basic exceptions
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2012 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 triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "Exceptions.h"
using namespace std;
using namespace triagens::basics;
// -----------------------------------------------------------------------------
// --SECTION-- public types
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Utilities
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief base class for all errors
////////////////////////////////////////////////////////////////////////////////
TriagensError::TriagensError (string const& type, string const& details, char const* file, int line)
: _type("unknown"),
_details(details),
_file(file),
_line(line) {
_message = "exception in '" + _file + "' at line " + StringUtils::itoa(_line) + ": "
+ "type = '" + _type + "'";
if (! details.empty()) {
_message += " details = '" + _details + "'";
}
}
TriagensError::~TriagensError () throw () {
}
char const * TriagensError::what () const throw() {
return _message.c_str();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for internal errors
////////////////////////////////////////////////////////////////////////////////
InternalError::InternalError (string const& details, char const* file, int line)
: TriagensError("internal error", details, file, line) {
}
InternalError::InternalError (std::exception const& ex, char const* file, int line)
: TriagensError("internal exception", ex.what(), file, line) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for out-of-memory errors
////////////////////////////////////////////////////////////////////////////////
OutOfMemoryError::OutOfMemoryError (char const* file, int line)
: TriagensError("out-of-memory", "", file, line) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for file errors
////////////////////////////////////////////////////////////////////////////////
FileError::FileError (string const& func,
string const& details,
string const& filename,
string const& mode,
int error,
char const* file,
int line)
: TriagensError("file-error", details, file, line),
_filename(filename),
_mode(mode),
_error(error) {
if (! mode.empty()) {
_message += " mode = '" + _mode + "'";
}
if (_error != 0) {
_message += " errno = " + StringUtils::itoa(_error) + ""
+ " error = '" + strerror(_error) + "'";
}
if (! _filename.empty()) {
_message += " file = '" + _filename + "'";
}
}
FileError::~FileError () throw () {
}
void FileError::setFilename (string const& filename) {
_filename = filename;
if (! _filename.empty()) {
_message += " file = '" + _filename + "'";
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for parse errors
////////////////////////////////////////////////////////////////////////////////
ParseError::ParseError (string const& details,
int lineNumber,
char const* file,
int line)
: TriagensError("parse-error", details, file, line),
_lineNumber(lineNumber) {
if (_lineNumber != -1) {
_message += " line-number = '" + StringUtils::itoa(_lineNumber) + "'";
}
}
void ParseError::setLineNumber (int lineNumber) {
_lineNumber = lineNumber;
if (_lineNumber != -1) {
_message += " line-number = '" + StringUtils::itoa(_lineNumber) + "'";
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for parameter errors
////////////////////////////////////////////////////////////////////////////////
ParameterError::ParameterError (string const& parameter,
string const& details,
string const& func,
char const* file,
int line)
: TriagensError("parameter-error", details, file, line),
_parameter(parameter),
_func(func) {
_message += " parameter = '" + _parameter + "'";
if (! _func.empty()) {
_message += " func = '" + _func + "'";
}
}
ParameterError::~ParameterError () throw () {
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -32,49 +32,7 @@
#include <errno.h>
#if BOOST_VERSION < 103600
#undef USE_BOOST_EXCEPTIONS
#else
#define USE_BOOST_EXCEPTIONS 1
#endif
#ifdef USE_BOOST_EXCEPTIONS
#if BOOST_VERSION < 104000
#include <boost/exception.hpp>
#else
#include <boost/exception/all.hpp>
#endif
#include <boost/exception/info.hpp>
#else
#include "Basics/StringUtils.h"
#endif
// -----------------------------------------------------------------------------
// --SECTION-- boost
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Utilities
/// @{
////////////////////////////////////////////////////////////////////////////////
#if defined(USE_BOOST_EXCEPTIONS) && (BOOST_VERSION < 104000)
namespace boost {
typedef error_info<struct errinfo_api_function_,char const *> errinfo_api_function;
typedef error_info<struct errinfo_at_line_,int> errinfo_at_line;
typedef error_info<struct errinfo_errno_,int> errinfo_errno;
typedef error_info<struct errinfo_file_name_,std::string> errinfo_file_name;
typedef error_info<struct errinfo_file_open_mode_,std::string> errinfo_file_open_mode;
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public macros
@ -89,347 +47,91 @@ namespace boost {
/// @brief diagnostic output
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define DIAGNOSTIC_INFORMATION(e) \
boost::diagnostic_information(e)
#else
#define DIAGNOSTIC_INFORMATION(e) \
e.diagnostic_information()
#endif
e.what()
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an unqualified exception
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_TRIAGENS_ERROR(mesg, details) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::TriagensError() \
<< triagens::ErrorMessage(mesg) \
<< triagens::ErrorDetails(details)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_TRIAGENS_ERROR(mesg, details) \
throw triagens::basics::TriagensError(mesg, details)
#endif
#define THROW_TRIAGENS_ERROR(type, details) \
throw triagens::basics::TriagensError(type, details, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for internal errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_INTERNAL_ERROR(a) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::InternalError() \
<< triagens::ErrorMessage(a) \
<< boost::errinfo_at_line(__LINE__) \
<< boost::errinfo_file_name(__FILE__)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_INTERNAL_ERROR(a) \
throw triagens::basics::InternalError(a)
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for internal errors with line info
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_INTERNAL_ERROR_L(a, file, line) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::InternalError() \
<< triagens::ErrorMessage(a) \
<< boost::errinfo_at_line(line) \
<< boost::errinfo_file_name(file)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_INTERNAL_ERROR_L(a, file, line) \
throw triagens::basics::InternalError(a)
#endif
#define THROW_INTERNAL_ERROR(details) \
throw triagens::basics::InternalError(details, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for out-of-memory errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_OUT_OF_MEMORY_ERROR() \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::OutOfMemoryError()); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_OUT_OF_MEMORY_ERROR() \
throw triagens::basics::OutOfMemoryError()
#endif
#define THROW_OUT_OF_MEMORY_ERROR() \
throw triagens::basics::OutOfMemoryError(__FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for file open errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_FILE_OPEN_ERROR(func, file, mode) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::FileError() \
<< triagens::ErrorMessage("file open error") \
<< boost::errinfo_api_function(func) \
<< boost::errinfo_errno(errno) \
<< boost::errinfo_file_name(file) \
<< boost::errinfo_file_open_mode(mode)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_FILE_OPEN_ERROR(func, file, mode) \
throw triagens::basics::FileError("file open error", file)
#endif
#define THROW_FILE_OPEN_ERROR(func, file, mode, error) \
throw triagens::basics::FileError(func, "file open error", file, mode, error, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for file errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_FILE_FUNC_ERROR(func, mesg) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::FileError() \
<< triagens::ErrorMessage(mesg) \
<< boost::errinfo_api_function(func) \
<< boost::errinfo_errno(errno)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_FILE_FUNC_ERROR(func, mesg) \
throw triagens::basics::FileError(func, mesg)
#endif
#define THROW_FILE_FUNC_ERROR(func, details, error) \
throw triagens::basics::FileError(func, details, "", "", error, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for file errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_FILE_FUNC_ERROR_E(func, mesg, error) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::FileError() \
<< triagens::ErrorMessage(mesg) \
<< boost::errinfo_api_function(func) \
<< boost::errinfo_errno(error)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_FILE_FUNC_ERROR_E(func, mesg, error) \
throw triagens::basics::FileError(func, mesg + (" " + triagens::basics::StringUtils::itoa(error)))
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for file errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_FILE_ERROR(mesg) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::FileError() \
<< triagens::ErrorMessage(mesg)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_FILE_ERROR(mesg) \
throw triagens::basics::FileError(mesg)
#endif
#define THROW_FILE_ERROR(details, error) \
throw triagens::basics::FileError("<unknown>", details, "", "", error, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief rethrows an exception with filename
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define RETHROW_FILE_NAME(ex, file) \
do { \
ex << boost::errinfo_file_name(file); \
throw ex; \
} while (0)
#else
#define RETHROW_FILE_NAME(ex, file) \
throw ex
#endif
#define RETHROW_FILE_NAME(ex, file) \
do { \
ex.setFilename(file); \
throw ex; \
} while (0)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for parse errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_PARSE_ERROR(mesg) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \
<< triagens::ErrorMessage(mesg)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_PARSE_ERROR(mesg) \
throw triagens::basics::ParseError(mesg)
#endif
#define THROW_PARSE_ERROR(details) \
throw triagens::basics::ParseError(details, -1, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for parse errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_PARSE_ERROR_L(line, mesg) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \
<< triagens::ErrorMessage(mesg) \
<< boost::errinfo_at_line(line)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_PARSE_ERROR_L(line, mesg) \
throw triagens::basics::ParseError(mesg, "line " + triagens::basics::StringUtils::itoa(line))
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for parse errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_PARSE_ERROR_D(mesg, details) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::ParseError() \
<< triagens::ErrorMessage(mesg) \
<< triagens::ErrorDetails(details)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_PARSE_ERROR_D(mesg, details) \
throw triagens::basics::ParseError(mesg, details)
#endif
#define THROW_PARSE_ERROR_L(details, line) \
throw triagens::basics::ParseError(details, line, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @brief rethrows an exception with line
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define RETHROW_LINE(ex, line) \
do { \
ex << boost::errinfo_at_line(line); \
throw ex; \
} while (0)
#else
#define RETHROW_LINE(ex, line) \
throw ex
#endif
#define RETHROW_LINE(ex, line) \
do { \
ex.setLineNumber(line); \
throw ex; \
} while (0)
////////////////////////////////////////////////////////////////////////////////
/// @brief throws an exception for parameter errors
///
/// Some compilers do not know that BOOST_THROW_EXCEPTION never returns.
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
#define THROW_PARAMETER_ERROR(param, func, mesg) \
do { \
BOOST_THROW_EXCEPTION(triagens::basics::ParameterError() \
<< triagens::ErrorMessage(mesg) \
<< ErrorParameterName(param) \
<< boost::errinfo_api_function(func)); \
throw "this cannot happen"; \
} \
while (0)
#else
#define THROW_PARAMETER_ERROR(param, func, mesg) \
throw triagens::basics::ParameterError(mesg, param + string(" in ") + func)
#endif
#define THROW_PARAMETER_ERROR(parameter, details, func) \
throw triagens::basics::ParameterError(parameter, details, func, __FILE__, __LINE__)
////////////////////////////////////////////////////////////////////////////////
/// @}
@ -439,377 +141,132 @@ namespace boost {
// --SECTION-- public types
// -----------------------------------------------------------------------------
namespace triagens {
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Utilities
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief message info
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
typedef boost::error_info<struct TagMessage, std::string> ErrorMessage;
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief message details
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
typedef boost::error_info<struct TagDetails, std::string> ErrorDetails;
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief parameter name
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
typedef boost::error_info<struct TagParameterName, string> ErrorParameterName;
#endif
namespace triagens {
namespace basics {
////////////////////////////////////////////////////////////////////////////////
/// @brief base class for all errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
class TriagensError : public virtual std::exception, public virtual boost::exception {
public:
~TriagensError () throw() {
}
public:
char const * what () const throw() {
return "triagens error";
}
string description () const {
return boost::diagnostic_information(*this);
}
};
#else
class TriagensError : public virtual std::exception {
public:
TriagensError ()
: message("unknown") {
}
TriagensError (string const& type,
string const& details,
char const* file,
int line);
TriagensError (string mesg)
: message(mesg) {
}
TriagensError (string mesg, string details)
: message(mesg + " (" + details + ")") {
}
~TriagensError () throw() {
}
~TriagensError () throw ();
public:
string diagnostic_information () const {
return string(what()) + ": " + message;
}
char const * what () const throw();
string description () const {
return diagnostic_information();
}
char const * what () const throw() {
return "triagens error";
}
string const& details () const throw() {
return message;
}
private:
string const message;
protected:
string _message;
string _type;
string _details;
string _file;
int _line;
};
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for internal errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
struct InternalError : public TriagensError {
class InternalError : public TriagensError {
public:
InternalError () {
}
InternalError (string const& what) {
*this << ErrorMessage(what);
}
InternalError (std::exception const& ex) {
*this << ErrorMessage(ex.what());
}
public:
char const * what () const throw() {
return "internal error";
}
InternalError (string const& details, char const* file, int line);
InternalError (std::exception const& ex, char const* file, int line);
};
#else
struct InternalError : public TriagensError {
public:
InternalError () : TriagensError("internal error") {
}
InternalError (string mesg) : TriagensError(mesg) {
}
InternalError (std::exception const& ex) : TriagensError(ex.what()) {
}
public:
char const * what () const throw() {
return "internal error";
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for out-of-memory errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
struct OutOfMemoryError : public TriagensError {
class OutOfMemoryError : public TriagensError {
public:
char const * what () const throw() {
return "out-of-memory error";
}
OutOfMemoryError (char const* file, int line);
};
#else
struct OutOfMemoryError : public TriagensError {
public:
OutOfMemoryError () : TriagensError("out-of-memory") {
}
public:
char const * what () const throw() {
return "out-of-memory error";
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for file errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
struct FileError : public TriagensError {
class FileError : public TriagensError {
public:
char const * what () const throw() {
return "file error";
}
FileError (string const& func,
string const& details,
string const& filename,
string const& mode,
int error,
char const* file,
int line);
~FileError () throw ();
public:
void setFilename (string const&);
protected:
string _func;
string _filename;
string _mode;
int _error;
};
#else
struct FileError : public TriagensError {
public:
FileError () : TriagensError("file error") {
}
FileError (string mesg) : TriagensError(mesg) {
}
FileError (string mesg, string details) : TriagensError(mesg, details) {
}
public:
char const * what () const throw() {
return "file error";
}
};
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for parse errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
struct ParseError : public TriagensError {
public:
char const * what () const throw() {
return "parse error";
}
};
#else
struct ParseError : public TriagensError {
public:
ParseError () : TriagensError("parse error") {
}
ParseError (string mesg) : TriagensError(mesg) {
}
ParseError (string mesg, string details) : TriagensError(mesg, details) {
}
ParseError (string const& details,
int lineNumber,
char const* file,
int line);
public:
char const * what () const throw() {
return "parse error";
}
};
void setLineNumber (int);
#endif
protected:
int _lineNumber;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief exception for parameter errors
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
struct ParameterError : public TriagensError {
public:
char const * what () const throw() {
return "parameter error";
}
ParameterError (string const& parameter,
string const& details,
string const& func,
char const* file,
int line);
~ParameterError () throw ();
protected:
string _parameter;
string _func;
};
#else
struct ParameterError : public TriagensError {
public:
ParameterError () : TriagensError("parameter error") {
}
ParameterError (string mesg) : TriagensError(mesg) {
}
ParameterError (string mesg, string details) : TriagensError(mesg, details) {
}
public:
char const * what () const throw() {
return "parameter error";
}
};
#endif
}
}
// -----------------------------------------------------------------------------
// --SECTION-- boost
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Utilities
/// @{
////////////////////////////////////////////////////////////////////////////////
#ifdef USE_BOOST_EXCEPTIONS
/// @cond IGNORE
namespace boost {
#if BOOST_VERSION < 104300
#define TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE char const *
#else
#define TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE std::string
#endif
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::error_info<struct triagens::TagMessage, std::string>::tag_typeid_name () const {
return "message";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::error_info<struct TagDetails, std::string>::tag_typeid_name () const {
return "details";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::errinfo_errno::tag_typeid_name () const {
return "errno";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::errinfo_file_name::tag_typeid_name () const {
return "file name";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::errinfo_file_open_mode::tag_typeid_name () const {
return "file open mode";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::errinfo_api_function::tag_typeid_name () const {
return "api function";
}
template<>
inline
TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
boost::errinfo_at_line::tag_typeid_name () const {
return "at line";
}
#undef TRIAGENS_TAG_TYPEID_NAME_RETURN_TYPE
}
/// @endcond
#endif
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"

View File

@ -78,7 +78,7 @@ namespace triagens {
int fd = TRI_OPEN(filename.c_str(), O_RDONLY);
if (fd == -1) {
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY");
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY", errno);
}
char buffer[10240];
@ -95,7 +95,7 @@ namespace triagens {
TRI_CLOSE(fd);
LOGGER_TRACE << "read failed for '" << filename << "' with " << strerror(errno) << " and result " << n
<< " on fd " << fd;
THROW_FILE_FUNC_ERROR("read", strerror(errno));
THROW_FILE_FUNC_ERROR("read", "", errno);
}
result.appendText(buffer, n);
@ -114,7 +114,7 @@ namespace triagens {
int fd = TRI_OPEN(filename.c_str(), O_RDONLY);
if (fd == -1) {
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY");
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY", errno);
}
char buffer[10240];
@ -130,7 +130,7 @@ namespace triagens {
TRI_CLOSE(fd);
LOGGER_TRACE << "read failed for '" << filename << "' with " << strerror(errno) << " and result " << n
<< " on fd " << fd;
THROW_FILE_FUNC_ERROR("read", strerror(errno));
THROW_FILE_FUNC_ERROR("read", "", errno);
}
result.appendText(buffer, n);
@ -146,7 +146,7 @@ namespace triagens {
if (fd == -1) {
LOGGER_TRACE << "open failed for '" << filename << "' with " << strerror(errno);
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY | O_CREAT | O_TRUNC");
THROW_FILE_OPEN_ERROR("open", filename, "O_RDONLY | O_CREAT | O_TRUNC", errno);
}
char const* ptr = content.c_str();
@ -159,7 +159,7 @@ namespace triagens {
TRI_CLOSE(fd);
LOGGER_TRACE << "write failed for '" << filename << "' with " << strerror(errno) << " and result " << n
<< " on fd " << fd;
THROW_FILE_FUNC_ERROR("write", strerror(errno));
THROW_FILE_FUNC_ERROR("write", "", errno);
}
ptr += n;
@ -177,7 +177,7 @@ namespace triagens {
if (fd == -1) {
LOGGER_TRACE << "open failed for '" << filename << "' with " << strerror(errno);
THROW_FILE_OPEN_ERROR("open", filename, "O_WRONLY | O_CREAT | O_TRUNC");
THROW_FILE_OPEN_ERROR("open", filename, "O_WRONLY | O_CREAT | O_TRUNC", errno);
}
char const* ptr = content.c_str();
@ -190,7 +190,7 @@ namespace triagens {
TRI_CLOSE(fd);
LOGGER_TRACE << "write failed for '" << filename << "' with " << strerror(errno) << " and result " << n
<< " on fd " << fd;
THROW_FILE_FUNC_ERROR("write", strerror(errno));
THROW_FILE_FUNC_ERROR("write", "", errno);
}
ptr += n;

View File

@ -152,7 +152,7 @@ void DispatcherThread::run () {
}
catch (std::exception const& ex) {
try {
InternalError err(string("job failed with unknown in work: ") + ex.what());
InternalError err(string("job failed with unknown in work: ") + ex.what(), __FILE__, __LINE__);
job->handleError(err);
}
@ -177,7 +177,7 @@ void DispatcherThread::run () {
#endif
try {
InternalError err("job failed with unknown error in work");
InternalError err("job failed with unknown error in work", __FILE__, __LINE__);
job->handleError(err);
}

View File

@ -435,13 +435,13 @@ namespace triagens {
catch (std::exception const& ex) {
RequestStatisticsAgentSetExecuteError(handler);
basics::InternalError err(ex);
basics::InternalError err(ex, __FILE__, __LINE__);
handler->handleError(err);
}
catch (...) {
RequestStatisticsAgentSetExecuteError(handler);
basics::InternalError err;
basics::InternalError err("handleRequestDirectly", __FILE__, __LINE__);
handler->handleError(err);
}
@ -453,7 +453,7 @@ namespace triagens {
typename HF::GeneralResponse * response = handler->getResponse();
if (response == 0) {
basics::InternalError err("no response received from handler");
basics::InternalError err("no response received from handler", __FILE__, __LINE__);
handler->handleError(err);
response = handler->getResponse();

View File

@ -176,7 +176,7 @@ namespace triagens {
typename HF::GeneralResponse * response = handler->getResponse();
if (response == 0) {
basics::InternalError err("no response received from handler");
basics::InternalError err("no response received from handler", __FILE__, __LINE__);
handler->handleError(err);
response = handler->getResponse();

View File

@ -11,6 +11,7 @@
lib_libarango_a_SOURCES = \
lib/Basics/ConditionLocker.cpp \
lib/Basics/ConditionVariable.cpp \
lib/Basics/Exceptions.cpp \
lib/Basics/FileUtils.cpp \
lib/Basics/Initialise.cpp \
lib/Basics/LibraryLoader.cpp \

View File

@ -97,7 +97,7 @@ Url::Url (string const& urlName)
}
}
else {
THROW_PARAMETER_ERROR("url", "constructor", "url not valid");
THROW_PARAMETER_ERROR("url", "url not valid", "constructor");
}
}

View File

@ -142,7 +142,7 @@ void VariantMatrix2::print (StringBuffer& buffer, size_t) const {
vector<string> const& VariantMatrix2::getDimension (size_t n) const {
if (n >= 2) {
THROW_PARAMETER_ERROR("n", "getDimension", "too large");
THROW_PARAMETER_ERROR("n", "too large", "getDimension");
}
return _dimensions[n];
@ -162,11 +162,11 @@ vector< vector<VariantObject*> > const& VariantMatrix2::getValues () const {
VariantObject* VariantMatrix2::getValue (size_t x, size_t y) const {
if (_dimensions[0].size() <= x) {
THROW_PARAMETER_ERROR("x", "setValue", "too large");
THROW_PARAMETER_ERROR("x", "too large", "setValue");
}
if (_dimensions[1].size() <= y) {
THROW_PARAMETER_ERROR("y", "setValue", "too large");
THROW_PARAMETER_ERROR("y", "too large", "setValue");
}
if (_values.size() <= x) {
@ -188,11 +188,11 @@ VariantObject* VariantMatrix2::getValue (size_t x, size_t y) const {
void VariantMatrix2::setValue (size_t x, size_t y, VariantObject* object) {
if (_dimensions[0].size() <= x) {
THROW_PARAMETER_ERROR("x", "setValue", "too large");
THROW_PARAMETER_ERROR("x", "too large", "setValue");
}
if (_dimensions[1].size() <= y) {
THROW_PARAMETER_ERROR("y", "setValue", "too large");
THROW_PARAMETER_ERROR("y", "too large", "setValue");
}
if (_values.size() <= x) {
@ -218,7 +218,7 @@ void VariantMatrix2::setValue (size_t x, size_t y, VariantObject* object) {
size_t VariantMatrix2::addDimension (size_t n, string const& name) {
if (n >= 2) {
THROW_PARAMETER_ERROR("n", "addDimension", "too large");
THROW_PARAMETER_ERROR("n", "too large", "addDimension");
}
_dimensions[n].push_back(name);