Cosmos图小精灵nodejs-未处理的拒绝承诺



我正在使用gremlin节点包向Azure cosmos图数据库发送查询。对于正确的查询,它返回response,但对于不正确的查询则因错误而崩溃-未经处理的promise拒绝。我已经试着接球了,但还是没能接住。

我的代码[查询不正确]:-

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: rnnActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4anExceptionType : GraphSyntaxExceptionnExceptionMessage :rntGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.rnt1 Error(s)nSource : Microsoft.Azure.Cosmos.Gremlin.CorentGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4antContext : graphcomputentScope : graphparse-translate-outerntGraphInterOpStatusCode : QuerySyntaxErrorntHResult : 0x80131500rn (597)",

错误堆栈:-

{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "ResponseError: Server error: rnnActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4anExceptionType : GraphSyntaxExceptionnExceptionMessage :rntGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.rnt1 Error(s)nSource : Microsoft.Azure.Cosmos.Gremlin.CorentGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4antContext : graphcomputentScope : graphparse-translate-outerntGraphInterOpStatusCode : QuerySyntaxErrorntHResult : 0x80131500rn (597)",
"reason": {
"errorType": "ResponseError",
"errorMessage": "Server error: rnnActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4anExceptionType : GraphSyntaxExceptionnExceptionMessage :rntGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.rnt1 Error(s)nSource : Microsoft.Azure.Cosmos.Gremlin.CorentGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4antContext : graphcomputentScope : graphparse-translate-outerntGraphInterOpStatusCode : QuerySyntaxErrorntHResult : 0x80131500rn (597)",
"name": "ResponseError",
"statusCode": 597,
"statusMessage": "rnnActivityId : a3a04a88-7112-466b-99d9-9cf9413edd4anExceptionType : GraphSyntaxExceptionnExceptionMessage :rntGremlin query syntax error: Unsupported groovy language rule: 'parExpression' text: '('username'' @ line 1, column 40.rnt1 Error(s)nSource : Microsoft.Azure.Cosmos.Gremlin.CorentGremlinRequestId : a3a04a88-7112-466b-99d9-9cf9413edd4antContext : graphcomputentScope : graphparse-translate-outerntGraphInterOpStatusCode : QuerySyntaxErrorntHResult : 0x80131500rn",
"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 : 0x80131500r",
" (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 : 0x80131500r",
" (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)"
]
}

正如您在上面看到的,它在这里崩溃并抛出错误,但在上面的代码中从未调用过我的catch。

p.S:-以上代码在AWS lambda 中运行

未处理的异常与Gremlin库无关,而是我解析Gremlin响应的代码。我错误地分析了提交函数响应,结果代码崩溃,出现了未处理的异常

最新更新