From 374b65e0d7284dedbf0c0b4706fb0a4a108f0c7f Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Fri, 31 Aug 2012 10:49:36 +0200 Subject: [PATCH] issue #177: fixed wrong error message --- arangod/Ahuacatl/ahuacatl-codegen.c | 71 ++++++++++++++++------------- arangod/Ahuacatl/ahuacatl-codegen.h | 3 +- arangod/V8Server/v8-vocbase.cpp | 2 +- js/common/bootstrap/errors.js | 1 + js/common/bootstrap/js-errors.h | 1 + lib/BasicsC/errors.dat | 1 + lib/BasicsC/voc-errors.c | 1 + lib/BasicsC/voc-errors.h | 14 ++++++ 8 files changed, 61 insertions(+), 33 deletions(-) diff --git a/arangod/Ahuacatl/ahuacatl-codegen.c b/arangod/Ahuacatl/ahuacatl-codegen.c index 737ea0f8d6..7053cf98fb 100644 --- a/arangod/Ahuacatl/ahuacatl-codegen.c +++ b/arangod/Ahuacatl/ahuacatl-codegen.c @@ -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; } diff --git a/arangod/Ahuacatl/ahuacatl-codegen.h b/arangod/Ahuacatl/ahuacatl-codegen.h index b583340639..7816cd80bb 100644 --- a/arangod/Ahuacatl/ahuacatl-codegen.h +++ b/arangod/Ahuacatl/ahuacatl-codegen.h @@ -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; diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 354063e697..b394c29548 100755 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -1349,7 +1349,7 @@ static v8::Handle 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 errorObject = CreateErrorObjectAhuacatl(&context->_error); return scope.Close(v8::ThrowException(errorObject)); diff --git a/js/common/bootstrap/errors.js b/js/common/bootstrap/errors.js index 2fc57b2276..6e26d34a8f 100644 --- a/js/common/bootstrap/errors.js +++ b/js/common/bootstrap/errors.js @@ -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" }, diff --git a/js/common/bootstrap/js-errors.h b/js/common/bootstrap/js-errors.h index b0c2bc4391..2687be4308 100644 --- a/js/common/bootstrap/js-errors.h +++ b/js/common/bootstrap/js-errors.h @@ -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" diff --git a/lib/BasicsC/errors.dat b/lib/BasicsC/errors.dat index b60b5f35fd..244ebd2534 100755 --- a/lib/BasicsC/errors.dat +++ b/lib/BasicsC/errors.dat @@ -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." diff --git a/lib/BasicsC/voc-errors.c b/lib/BasicsC/voc-errors.c index efc847d0a4..a9d01078b0 100644 --- a/lib/BasicsC/voc-errors.c +++ b/lib/BasicsC/voc-errors.c @@ -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"); diff --git a/lib/BasicsC/voc-errors.h b/lib/BasicsC/voc-errors.h index cf7421c44c..db978edea4 100644 --- a/lib/BasicsC/voc-errors.h +++ b/lib/BasicsC/voc-errors.h @@ -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 ///