【发布时间】:2025-12-28 04:35:10
【问题描述】:
我正在使用 gremlin 节点包向 Azure cosmos graph db 发送查询。对于正确的查询,它会返回响应,但对于不正确的查询,它会因错误而崩溃 - 未处理的承诺拒绝。我尝试了 catch ,但它仍然没有被捕获。
我的代码[查询不正确]:-
module.exports.getUserRole = async (event) => {
console.log("In getUserRole");
return new Promise(async (resolve, reject)=> {
try {
const { P, g, translator, client } = await cosmos.getGraphTraversalhelpers();
console.log("P", P);
console.log("graphTraversal", g);
console.log("translator", translator);
console.log("client._connection", client._connection);
console.log("client._connection.addListener", client._connection.on);
let query = g
.V()
.hasLabel("user")
.has("userName", event)
.has("status", P.neq("disabled"))
.out("hasUserRole")
.has("status", P.neq("disabled"))
.valueMap(true)
.getBytecode(); // prepares the query
client._connection.on('error', (error) => {
console.log('addListener', error);
reject(error);
})
let queryResult = await cosmos.executeQuery(translator.translate(query));
console.log("executeQuery is", query);
// driver.close(); // closes the db driver
if (Array.isArray(queryResult) && queryResult.length > 0) {
queryResult = queryResult[0];
}
return queryResult;
} catch (error) {
console.log("getUserRole cosmosgraph dao", error);
reject(error);
}
});
};
错误信息:-
"errorMessage": "ResponseError: Server error: \r\n\nActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType : GraphSyntaxException\nExceptionMessage :\r\n\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r\n\t1 Error(s)\nSource : Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a\n\tContext : graphcompute\n\tScope : graphparse-translate-outer\n\tGraphInterOpStatusCode : QuerySyntaxError\n\tHResult : 0x80131500\r\n (597)",
错误堆栈:-
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "ResponseError: Server error: \r\n\nActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType : GraphSyntaxException\nExceptionMessage :\r\n\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r\n\t1 Error(s)\nSource : Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a\n\tContext : graphcompute\n\tScope : graphparse-translate-outer\n\tGraphInterOpStatusCode : QuerySyntaxError\n\tHResult : 0x80131500\r\n (597)",
"reason": {
"errorType": "ResponseError",
"errorMessage": "Server error: \r\n\nActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType : GraphSyntaxException\nExceptionMessage :\r\n\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r\n\t1 Error(s)\nSource : Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a\n\tContext : graphcompute\n\tScope : graphparse-translate-outer\n\tGraphInterOpStatusCode : QuerySyntaxError\n\tHResult : 0x80131500\r\n (597)",
"name": "ResponseError",
"statusCode": 597,
"statusMessage": "\r\n\nActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType : GraphSyntaxException\nExceptionMessage :\r\n\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r\n\t1 Error(s)\nSource : Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a\n\tContext : graphcompute\n\tScope : graphparse-translate-outer\n\tGraphInterOpStatusCode : QuerySyntaxError\n\tHResult : 0x80131500\r\n",
"statusAttributes": {
"x-ms-status-code": 400,
"x-ms-request-charge": 0,
"x-ms-total-request-charge": 0,
"x-ms-server-time-ms": 1.3698,
"x-ms-total-server-time-ms": 1.3698,
"x-ms-activity-id": "a3a04a88-7112-466b-99d9-9cf9413edd4a"
},
"stack": [
"ResponseError: Server error: \r",
"",
"ActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a",
"ExceptionType : GraphSyntaxException",
"ExceptionMessage :\r",
"\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r",
"\t1 Error(s)",
"Source : Microsoft.Azure.Cosmos.Gremlin.Core",
"\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a",
"\tContext : graphcompute",
"\tScope : graphparse-translate-outer",
"\tGraphInterOpStatusCode : QuerySyntaxError",
"\tHResult : 0x80131500\r",
" (597)",
" at Connection._handleMessage (/opt/nodejs/node_modules/gremlin/lib/driver/connection.js:289:9)",
" at WebSocket.<anonymous> (/opt/nodejs/node_modules/gremlin/lib/driver/connection.js:131:43)",
" at WebSocket.emit (events.js:314:20)",
" at WebSocket.EventEmitter.emit (domain.js:483:12)",
" at Receiver.receiverOnMessage (/opt/nodejs/node_modules/ws/lib/websocket.js:789:20)",
" at Receiver.emit (events.js:314:20)",
" at Receiver.EventEmitter.emit (domain.js:483:12)",
" at Receiver.dataMessage (/opt/nodejs/node_modules/ws/lib/receiver.js:413:14)",
" at Receiver.getData (/opt/nodejs/node_modules/ws/lib/receiver.js:352:17)",
" at Receiver.startLoop (/opt/nodejs/node_modules/ws/lib/receiver.js:138:22)"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: ResponseError: Server error: \r",
"",
"ActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4a",
"ExceptionType : GraphSyntaxException",
"ExceptionMessage :\r",
"\tGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.\r",
"\t1 Error(s)",
"Source : Microsoft.Azure.Cosmos.Gremlin.Core",
"\tGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4a",
"\tContext : graphcompute",
"\tScope : graphparse-translate-outer",
"\tGraphInterOpStatusCode : QuerySyntaxError",
"\tHResult : 0x80131500\r",
" (597)",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at process.EventEmitter.emit (domain.js:483:12)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
正如您在上面看到的,它崩溃了 here 并抛出错误,但我的 catch 从未在上面的代码中调用。
P.S:- 以上代码在 AWS lambda 中运行
【问题讨论】:
标签: azure azure-cosmosdb azure-cosmosdb-gremlinapi