1
0
Fork 0

issue #177: fixed wrong error message

This commit is contained in:
Jan Steemann 2012-08-31 10:49:36 +02:00
parent ebbac1891a
commit 374b65e0d7
8 changed files with 61 additions and 33 deletions

View File

@ -202,7 +202,7 @@ static inline void ScopeOutput (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputString(scope->_buffer, value)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -215,7 +215,7 @@ static inline void ScopeOutputInt (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputInt(scope->_buffer, value)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -228,7 +228,7 @@ static inline void ScopeOutputUInt (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputUInt(scope->_buffer, value)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -241,13 +241,13 @@ static inline void ScopeOutputQuoted (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputChar(scope->_buffer, '\'')) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
if (!OutputString(scope->_buffer, value)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
if (!OutputChar(scope->_buffer, '\'')) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -262,23 +262,23 @@ static inline void ScopeOutputQuoted2 (TRI_aql_codegen_js_t* const generator,
size_t outLength;
if (!OutputChar(scope->_buffer, '"')) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
escaped = TRI_EscapeUtf8StringZ(TRI_UNKNOWN_MEM_ZONE, value, strlen(value), false, &outLength);
if (escaped) {
if (!OutputString(scope->_buffer, escaped)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, escaped);
}
else {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
if (!OutputChar(scope->_buffer, '"')) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -295,7 +295,7 @@ static inline void ScopeOutputJson (TRI_aql_codegen_js_t* const generator,
}
if (TRI_StringifyJson(scope->_buffer, json) != TRI_ERROR_NO_ERROR) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -322,10 +322,10 @@ static inline void ScopeOutputFunction (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputString(scope->_buffer, FUNCTION_PREFIX)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
if (!OutputInt(scope->_buffer, (int64_t) functionIndex)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -338,10 +338,10 @@ static inline void ScopeOutputRegister (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_scope_t* scope = CurrentScope(generator);
if (!OutputString(scope->_buffer, REGISTER_PREFIX)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
if (!OutputInt(scope->_buffer, (int64_t) registerIndex)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -432,7 +432,7 @@ static void StartScope (TRI_aql_codegen_js_t* const generator,
scope = (TRI_aql_codegen_scope_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_codegen_scope_t), false);
if (!scope) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
return;
}
@ -637,14 +637,15 @@ static void EnterSymbol (TRI_aql_codegen_js_t* const generator,
TRI_aql_codegen_variable_t* variable = CreateVariable(name, registerIndex);
if (!variable) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
return;
}
if (TRI_InsertKeyAssociativePointer(&scope->_variables, name, (void*) variable, false)) {
// variable already exists in symbol table. this should never happen
TRI_AQL_LOG("variable already registered: %s", name);
generator->_error = true;
generator->_errorCode = TRI_ERROR_QUERY_VARIABLE_REDECLARED;
generator->_errorValue = (char*) name;
}
}
@ -673,7 +674,8 @@ static TRI_aql_codegen_register_t LookupSymbol (TRI_aql_codegen_js_t* const gene
// variable not found. this should never happen
TRI_AQL_LOG("variable not found: %s", name);
generator->_error = true;
generator->_errorCode = TRI_ERROR_QUERY_VARIABLE_NAME_UNKNOWN;
generator->_errorValue = (char*) name;
return 0;
}
@ -1122,7 +1124,7 @@ static void ProcessValue (TRI_aql_codegen_js_t* const generator,
}
if (!TRI_ValueJavascriptAql(scope->_buffer, &node->_value, node->_value._type)) {
generator->_error = true;
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
@ -1287,7 +1289,7 @@ static void ProcessCollectionHinted (TRI_aql_codegen_js_t* const generator,
case TRI_IDX_TYPE_CAP_CONSTRAINT:
case TRI_IDX_TYPE_BITARRAY_INDEX:
// these index types are not yet supported
generator->_error = true;
generator->_errorCode = TRI_ERROR_INTERNAL;
break;
case TRI_IDX_TYPE_PRIMARY_INDEX:
@ -2223,7 +2225,8 @@ static TRI_aql_codegen_js_t* CreateGenerator (TRI_aql_context_t* const context)
TRI_InitStringBuffer(&generator->_functionBuffer, TRI_UNKNOWN_MEM_ZONE);
TRI_InitVectorPointer(&generator->_scopes, TRI_UNKNOWN_MEM_ZONE);
generator->_error = false;
generator->_errorCode = TRI_ERROR_NO_ERROR;
generator->_errorValue = NULL;
generator->_registerIndex = 0;
generator->_functionIndex = 0;
@ -2271,21 +2274,27 @@ char* TRI_GenerateCodeAql (TRI_aql_context_t* const context) {
OutputString(&generator->_buffer, "})()");
if (generator->_error) {
FreeGenerator(generator);
code = NULL;
return NULL;
if (generator->_errorCode == TRI_ERROR_NO_ERROR) {
// put everything together
code = TRI_Concatenate2StringZ(TRI_UNKNOWN_MEM_ZONE, generator->_functionBuffer._buffer, generator->_buffer._buffer);
if (code) {
TRI_AQL_DUMP("generated code: %s\n", code);
}
else {
generator->_errorCode = TRI_ERROR_OUT_OF_MEMORY;
}
}
// put everything together
code = TRI_Concatenate2String(generator->_functionBuffer._buffer, generator->_buffer._buffer);
if (generator->_errorCode != TRI_ERROR_NO_ERROR) {
// register the error
TRI_SetErrorContextAql(context, generator->_errorCode, generator->_errorValue);
}
assert(generator);
FreeGenerator(generator);
if (code) {
TRI_AQL_DUMP("generated code: %s\n", code);
}
return code;
}

View File

@ -99,7 +99,8 @@ typedef struct TRI_aql_codegen_js_s {
size_t _registerIndex;
size_t _functionIndex;
bool _error;
int _errorCode; // error number
char* _errorValue; // error context string
}
TRI_aql_codegen_js_t;

View File

@ -1349,7 +1349,7 @@ static v8::Handle<v8::Value> ExecuteQueryNativeAhuacatl (TRI_aql_context_t* cons
// generate code
char* code = TRI_GenerateCodeAql(context);
if (!code) {
if (! code || context->_error._code != TRI_ERROR_NO_ERROR) {
v8::Handle<v8::Object> errorObject = CreateErrorObjectAhuacatl(&context->_error);
return scope.Close(v8::ThrowException(errorObject));

View File

@ -79,6 +79,7 @@
"ERROR_QUERY_NUMBER_OUT_OF_RANGE" : { "code" : 1504, "message" : "number out of range" },
"ERROR_QUERY_VARIABLE_NAME_INVALID" : { "code" : 1510, "message" : "variable name '%s' has an invalid format" },
"ERROR_QUERY_VARIABLE_REDECLARED" : { "code" : 1511, "message" : "variable '%s' is assigned multiple times" },
"ERROR_QUERY_VARIABLE_NAME_UNKNOWN" : { "code" : 1512, "message" : "unknown variable '%s'" },
"ERROR_QUERY_COLLECTION_NOT_FOUND" : { "code" : 1520, "message" : "unable to open collection '%s'" },
"ERROR_QUERY_COLLECTION_LOCK_FAILED" : { "code" : 1521, "message" : "unable to read-lock collection %s" },
"ERROR_QUERY_TOO_MANY_COLLECTIONS" : { "code" : 1522, "message" : "too many collections" },

View File

@ -80,6 +80,7 @@ static string JS_common_bootstrap_errors =
" \"ERROR_QUERY_NUMBER_OUT_OF_RANGE\" : { \"code\" : 1504, \"message\" : \"number out of range\" }, \n"
" \"ERROR_QUERY_VARIABLE_NAME_INVALID\" : { \"code\" : 1510, \"message\" : \"variable name '%s' has an invalid format\" }, \n"
" \"ERROR_QUERY_VARIABLE_REDECLARED\" : { \"code\" : 1511, \"message\" : \"variable '%s' is assigned multiple times\" }, \n"
" \"ERROR_QUERY_VARIABLE_NAME_UNKNOWN\" : { \"code\" : 1512, \"message\" : \"unknown variable '%s'\" }, \n"
" \"ERROR_QUERY_COLLECTION_NOT_FOUND\" : { \"code\" : 1520, \"message\" : \"unable to open collection '%s'\" }, \n"
" \"ERROR_QUERY_COLLECTION_LOCK_FAILED\" : { \"code\" : 1521, \"message\" : \"unable to read-lock collection %s\" }, \n"
" \"ERROR_QUERY_TOO_MANY_COLLECTIONS\" : { \"code\" : 1522, \"message\" : \"too many collections\" }, \n"

View File

@ -109,6 +109,7 @@ ERROR_QUERY_SCRIPT,1503,"runtime error '%s'","Will be raised when a runtime erro
ERROR_QUERY_NUMBER_OUT_OF_RANGE,1504,"number out of range","Will be raised when a number is outside the expected range."
ERROR_QUERY_VARIABLE_NAME_INVALID,1510,"variable name '%s' has an invalid format","Will be raised when an invalid variable name is used."
ERROR_QUERY_VARIABLE_REDECLARED,1511,"variable '%s' is assigned multiple times","Will be raised when a variable gets re-assigned in a query."
ERROR_QUERY_VARIABLE_NAME_UNKNOWN,1512,"unknown variable '%s'","Will be raised when an unknown variable is used or the variable is undefined the context it is used."
ERROR_QUERY_COLLECTION_NOT_FOUND,1520,"unable to open collection '%s'","Will be raised when one of the collections referenced in the query was not found."
ERROR_QUERY_COLLECTION_LOCK_FAILED,1521,"unable to read-lock collection %s","Will be raised when a read lock on the collection cannot be acquired."
ERROR_QUERY_TOO_MANY_COLLECTIONS,1522,"too many collections","Will be raised when the number of collections in a query is beyond the allowed value."

View File

@ -75,6 +75,7 @@ void TRI_InitialiseErrorMessages (void) {
REG_ERROR(ERROR_QUERY_NUMBER_OUT_OF_RANGE, "number out of range");
REG_ERROR(ERROR_QUERY_VARIABLE_NAME_INVALID, "variable name '%s' has an invalid format");
REG_ERROR(ERROR_QUERY_VARIABLE_REDECLARED, "variable '%s' is assigned multiple times");
REG_ERROR(ERROR_QUERY_VARIABLE_NAME_UNKNOWN, "unknown variable '%s'");
REG_ERROR(ERROR_QUERY_COLLECTION_NOT_FOUND, "unable to open collection '%s'");
REG_ERROR(ERROR_QUERY_COLLECTION_LOCK_FAILED, "unable to read-lock collection %s");
REG_ERROR(ERROR_QUERY_TOO_MANY_COLLECTIONS, "too many collections");

View File

@ -153,6 +153,9 @@ extern "C" {
/// Will be raised when an invalid variable name is used.
/// - 1511: @CODE{variable '\%s' is assigned multiple times}
/// Will be raised when a variable gets re-assigned in a query.
/// - 1512: @CODE{unknown variable '\%s'}
/// Will be raised when an unknown variable is used or the variable is
/// undefined the context it is used.
/// - 1520: @CODE{unable to open collection '\%s'}
/// Will be raised when one of the collections referenced in the query was
/// not found.
@ -993,6 +996,17 @@ void TRI_InitialiseErrorMessages (void);
#define TRI_ERROR_QUERY_VARIABLE_REDECLARED (1511)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1512: ERROR_QUERY_VARIABLE_NAME_UNKNOWN
///
/// unknown variable '%s'
///
/// Will be raised when an unknown variable is used or the variable is
/// undefined the context it is used.
////////////////////////////////////////////////////////////////////////////////
#define TRI_ERROR_QUERY_VARIABLE_NAME_UNKNOWN (1512)
////////////////////////////////////////////////////////////////////////////////
/// @brief 1520: ERROR_QUERY_COLLECTION_NOT_FOUND
///