From ec67a07f9b90452368b65e2087a847c7ea29f2e2 Mon Sep 17 00:00:00 2001 From: Willi Goesgens Date: Wed, 3 Sep 2014 16:13:35 +0200 Subject: [PATCH] Parser: when throwing parse exceptions add the query and a pointer to the actual indicated error to the message. --- arangod/Aql/Parser.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/arangod/Aql/Parser.cpp b/arangod/Aql/Parser.cpp index e062f71338..31810a3354 100644 --- a/arangod/Aql/Parser.cpp +++ b/arangod/Aql/Parser.cpp @@ -178,15 +178,35 @@ void Parser::registerParseError (int errorCode, // extract the query string part where the error happened std::string const region(_query->extractRegion(line, column)); + // create a neat pointer to the location of the error. + auto arrowpointer = (char*) malloc (sizeof(char) * (column + 10) ); + size_t i; + for (i = 0; i < (size_t) column; i++) { + arrowpointer[i] = ' '; + } + if (i > 0) { + i --; + arrowpointer[i++] = '^'; + } + + arrowpointer[i++] = '^'; + arrowpointer[i++] = '^'; + arrowpointer[i++] = '\0'; + + // note: line numbers reported by bison/flex start at 1, columns start at 0 char buffer[512]; snprintf(buffer, sizeof(buffer), - "%s near '%s' at position %d:%d", + "%s near '%s' at position %d:%d:\n%s\n%s\n", data, region.c_str(), line, - column + 1); + column + 1, + _query->queryString(), + arrowpointer); + + free(arrowpointer); registerError(errorCode, buffer); }