1
0
Fork 0

fixed error messages and tests

This commit is contained in:
Frank Celler 2013-04-02 17:46:19 +02:00
parent 3512fa6ff0
commit 42b92c794f
11 changed files with 53 additions and 23 deletions

View File

@ -453,7 +453,7 @@ int AttributeNamesFromArguments (v8::Arguments const& argv,
error = "invalid attribute name";
TRI_FreeContentVectorPointer(TRI_CORE_MEM_ZONE, result);
return TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
}
TRI_Utf8ValueNFC argumentString(TRI_UNKNOWN_MEM_ZONE, argument);
@ -471,7 +471,7 @@ int AttributeNamesFromArguments (v8::Arguments const& argv,
error = "invalid attribute name";
TRI_FreeContentVectorPointer(TRI_CORE_MEM_ZONE, result);
return TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
}
TRI_PushBackVectorPointer(result, cArgument);
@ -491,7 +491,7 @@ int AttributeNamesFromArguments (v8::Arguments const& argv,
error = "duplicate attribute names";
TRI_FreeContentVectorPointer(TRI_CORE_MEM_ZONE, result);
return TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION);
return TRI_set_errno(TRI_ERROR_BAD_PARAMETER);
}
}
@ -3703,7 +3703,7 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (! argument->IsString() ) {
errorString = "invalid parameter -- expected string parameter";
errorCode = TRI_ERROR_ILLEGAL_OPTION;
errorCode = TRI_ERROR_BAD_PARAMETER;
ok = false;
break;
}
@ -3722,12 +3722,11 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (! argument->IsArray() ) {
errorString = "invalid parameter -- expected an array (list)";
errorCode = TRI_ERROR_ILLEGAL_OPTION;
errorCode = TRI_ERROR_BAD_PARAMETER;
ok = false;
break;
}
// .........................................................................
// Attempt to convert the V8 javascript function argument into a TRI_json_t
// .........................................................................
@ -3741,7 +3740,7 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (value == 0) {
errorString = "invalid parameter -- expected an array (list)";
errorCode = TRI_ERROR_ILLEGAL_OPTION;
errorCode = TRI_ERROR_BAD_PARAMETER;
ok = false;
break;
}
@ -3753,7 +3752,7 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (value->_type != TRI_JSON_LIST) {
errorString = "invalid parameter -- expected an array (list)";
errorCode = TRI_ERROR_ILLEGAL_OPTION;
errorCode = TRI_ERROR_BAD_PARAMETER;
ok = false;
break;
}
@ -3772,13 +3771,11 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (attributes._length != values._length) {
errorString = "invalid parameter -- expected an array (list)";
errorCode = TRI_ERROR_ILLEGAL_OPTION;
errorCode = TRI_ERROR_BAD_PARAMETER;
ok = false;
}
}
// .............................................................................
// Actually create the index here
// .............................................................................
@ -3786,6 +3783,7 @@ static v8::Handle<v8::Value> EnsureBitarray (v8::Arguments const& argv, bool sup
if (ok) {
char* errorStr = 0;
bitarrayIndex = TRI_EnsureBitarrayIndexDocumentCollection(document, &attributes, &values, supportUndef, &indexCreated, &errorCode, &errorStr);
if (bitarrayIndex == 0) {
if (errorStr == 0) {
errorString = "index could not be created from Simple Collection";

View File

@ -2780,7 +2780,7 @@ TRI_index_t* TRI_CreateBitarrayIndex (struct TRI_primary_collection_s* primary,
if (valueList == NULL || valueList->_type != TRI_JSON_LIST) {
LOG_WARNING("bitarray index creation failed -- list of values for index undefined");
*errorNum = TRI_ERROR_ILLEGAL_OPTION;
*errorNum = TRI_ERROR_BAD_PARAMETER;
*errorStr = TRI_DuplicateString("bitarray index creation failed -- list of values for index undefined");
return NULL;
}

View File

@ -32,6 +32,7 @@
"ERROR_FILE_NOT_FOUND" : { "code" : 14, "message" : "file not found" },
"ERROR_CANNOT_WRITE_FILE" : { "code" : 15, "message" : "cannot write file" },
"ERROR_CANNOT_OVERWRITE_FILE" : { "code" : 16, "message" : "cannot overwrite file" },
"ERROR_TYPE_ERROR" : { "code" : 17, "message" : "type error" },
"ERROR_HTTP_BAD_PARAMETER" : { "code" : 400, "message" : "bad parameter" },
"ERROR_HTTP_FORBIDDEN" : { "code" : 403, "message" : "forbidden" },
"ERROR_HTTP_NOT_FOUND" : { "code" : 404, "message" : "not found" },

View File

@ -287,7 +287,13 @@ exports.printTable = function (list, columns, framed) {
fixedLength = columns[col] >= pad.length ? columns[col] : pad.length;
}
descriptions.push({ id: col, name: col, fixedLength: fixedLength, length: fixedLength || col.length });
descriptions.push({
id: col,
name: col,
fixedLength: fixedLength,
length: fixedLength || col.length
});
matrix[0][j++] = col;
}
}

View File

@ -90,18 +90,23 @@ exports.createHelpHeadline = function (text) {
// must came after the export of createHelpHeadline
var ArangoError = require("org/arangodb/arango-error").ArangoError;
var arangodb = require("org/arangodb");
exports.checkRequestResult = function (requestResult) {
if (requestResult === undefined) {
requestResult = {
"error" : true,
"code" : 0,
"errorNum" : 0,
"code" : 500,
"errorNum" : arangodb.ERROR_INTERNAL,
"errorMessage" : "Unknown error. Request result is empty"
};
}
if (requestResult.error !== undefined && requestResult.error) {
if (requestResult.errorNum === arangodb.ERROR_TYPE_ERROR) {
throw new TypeError(requestResult.errorMessage);
}
throw new ArangoError(requestResult);
}
};

View File

@ -89,18 +89,23 @@ exports.createHelpHeadline = function (text) {
// must came after the export of createHelpHeadline
var ArangoError = require("org/arangodb/arango-error").ArangoError;
var arangodb = require("org/arangodb");
exports.checkRequestResult = function (requestResult) {
if (requestResult === undefined) {
requestResult = {
"error" : true,
"code" : 0,
"errorNum" : 0,
"code" : 500,
"errorNum" : arangodb.ERROR_INTERNAL,
"errorMessage" : "Unknown error. Request result is empty"
};
}
if (requestResult.error !== undefined && requestResult.error) {
if (requestResult.errorNum === arangodb.ERROR_TYPE_ERROR) {
throw new TypeError(requestResult.errorMessage);
}
throw new ArangoError(requestResult);
}
};

View File

@ -32,6 +32,7 @@
"ERROR_FILE_NOT_FOUND" : { "code" : 14, "message" : "file not found" },
"ERROR_CANNOT_WRITE_FILE" : { "code" : 15, "message" : "cannot write file" },
"ERROR_CANNOT_OVERWRITE_FILE" : { "code" : 16, "message" : "cannot overwrite file" },
"ERROR_TYPE_ERROR" : { "code" : 17, "message" : "type error" },
"ERROR_HTTP_BAD_PARAMETER" : { "code" : 400, "message" : "bad parameter" },
"ERROR_HTTP_FORBIDDEN" : { "code" : 403, "message" : "forbidden" },
"ERROR_HTTP_NOT_FOUND" : { "code" : 404, "message" : "not found" },

View File

@ -1639,10 +1639,10 @@ function resultException (req, res, err, headers) {
}
if (msg === "") {
msg = String(err) + " " + String(err.stack);
msg = String(err) + ": " + String(err.stack);
}
else {
msg += " " + String(err.stack);
msg += ": " + String(err.stack);
}
switch (num) {
@ -1659,9 +1659,9 @@ function resultException (req, res, err, headers) {
resultError(req, res, code, num, msg, headers);
}
else if (err instanceof TypeError) {
num = arangodb.ERROR_HTTP_BAD_PARAMETER;
num = arangodb.ERROR_TYPE_ERROR;
code = exports.HTTP_BAD;
msg = String(err.message) + " " + String(err.stack);
msg = String(err.message) + ": " + String(err.stack);
resultError(req, res, code, num, msg, headers);
}

View File

@ -19,6 +19,7 @@ ERROR_CORRUPTED_CSV,13,"csv is corrupt","Will be raised when encountering a corr
ERROR_FILE_NOT_FOUND,14,"file not found","Will be raised when a file is not found."
ERROR_CANNOT_WRITE_FILE,15,"cannot write file","Will be raised when a file cannot be written."
ERROR_CANNOT_OVERWRITE_FILE,16,"cannot overwrite file","Will be raised when an attempt is made to overwrite an existing file."
ERROR_TYPE_ERROR,17,"type error","Will be raised when a type error is unencountered."
################################################################################
## HTTP standard errors

View File

@ -28,6 +28,7 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_FILE_NOT_FOUND, "file not found");
REG_ERROR(ERROR_CANNOT_WRITE_FILE, "cannot write file");
REG_ERROR(ERROR_CANNOT_OVERWRITE_FILE, "cannot overwrite file");
REG_ERROR(ERROR_TYPE_ERROR, "type error");
REG_ERROR(ERROR_HTTP_BAD_PARAMETER, "bad parameter");
REG_ERROR(ERROR_HTTP_FORBIDDEN, "forbidden");
REG_ERROR(ERROR_HTTP_NOT_FOUND, "not found");

View File

@ -1,6 +1,6 @@
#ifndef TRIAGENS_BASICS_C_ERRORS_H
#define TRIAGENS_BASICS_C_ERRORS_H 1
#ifndef TRIAGENS_BASICS_C_VOC_ERRORS_H
#define TRIAGENS_BASICS_C_VOC_ERRORS_H 1
#ifdef __cplusplus
extern "C" {
@ -45,6 +45,8 @@ extern "C" {
/// Will be raised when a file cannot be written.
/// - 16: @LIT{cannot overwrite file}
/// Will be raised when an attempt is made to overwrite an existing file.
/// - 17: @LIT{type error}
/// Will be raised when a type error is unencountered.
/// - 400: @LIT{bad parameter}
/// Will be raised when the HTTP request does not fulfill the requirements.
/// - 403: @LIT{forbidden}
@ -565,6 +567,16 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_CANNOT_OVERWRITE_FILE (16)
////////////////////////////////////////////////////////////////////////////////
/// @brief 17: ERROR_TYPE_ERROR
///
/// type error
///
/// Will be raised when a type error is unencountered.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_TYPE_ERROR (17)
////////////////////////////////////////////////////////////////////////////////
/// @brief 400: ERROR_HTTP_BAD_PARAMETER
///