Azure cosmosdb 宇宙图小精灵nodejs-未处理的承诺拒绝
我正在使用Azure cosmosdb 宇宙图小精灵nodejs-未处理的承诺拒绝,azure-cosmosdb,gremlin,graph-databases,azure-cosmosdb-gremlinapi,cosmos,Azure Cosmosdb,Gremlin,Graph Databases,Azure Cosmosdb Gremlinapi,Cosmos,我正在使用gremlin节点包向Azure cosmos graph db发送查询。对于正确的查询,它返回响应,但对于错误的查询,它会因错误而崩溃-未处理的承诺拒绝。我已经试过了,但还是没有成功 我的代码[不正确的查询]:- module.exports.getUserRole = async (event) => { console.log("In getUserRole"); return new Promise(async (resolve, reject
gremlin
节点包向Azure cosmos graph db发送查询。对于正确的查询,它返回响应,但对于错误的查询,它会因错误而崩溃-未处理的承诺拒绝。我已经试过了,但还是没有成功
我的代码[不正确的查询]:-
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)"
]
}
{
“errorType”:“Runtime.UnhandledPromiserExtraction”,
“errorMessage:“ResponseError:服务器错误:\r\n\nActivityId:a3a04a88-7112-466b-99d9-9cf9413edd4a\nException类型:GraphSyntaxException\nExceptionMessage:\r\n\tGremlin查询语法错误:不支持的groovy语言规则:“parExpression”text:(“用户名”@第1行,第40列)。\r\n\t1错误\nSource:Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId:a3a04a88-7112-466b-99d9-9cf9413edd4a\n\t上下文:graphcompute\n\t作用域:graphparse翻译外部\n\tgraphInteropStatus代码:QuerySyntaxError\n\t结果:0x80131500\r\n(597)”,
“理由”:{
“errorType”:“ResponseError”,
“errorMessage”:“服务器错误:\r\n\nActivityId:a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType:GraphSyntaxException\nExceptionMessage:\r\n\tGremlin查询语法错误:不受支持的groovy语言规则:“parExpression”text:“(用户名“”@第1行,第40列)。\r\n\t1错误)\nSource:Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId:a3a04a88-7112-466b-99d9-9cf9413edd4a\n\t上下文:graphcompute\n\t作用域:graphparse翻译外部\n\tgraphInteropStatus代码:QuerySyntaxError\n\t结果:0x80131500\r\n(597)”,
“名称”:“响应者错误”,
“状态代码”:597,
“statusMessage”:“\r\n\nActivityId:a3a04a88-7112-466b-99d9-9cf9413edd4a\nExceptionType:GraphSyntaxException\nExceptionMessage:\r\n\tGremlin查询语法错误:不受支持的groovy语言规则:“parExpression”text:”(“用户名”@第1行,第40列。\r\n\t1错误)\nSource:Microsoft.Azure.Cosmos.Gremlin.Core\n\tGremlinRequestId:a3a04a88-7112-466b-99d9-9cf9413edd4a\n\t上下文:graphcompute\n\t作用域:graphparse翻译外部\n\tgraphInteropStatus代码:QuerySyntaxError\n\t结果:0x80131500\r\n“,
“状态属性”:{
“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”
},
“堆栈”:[
“ResponseError:服务器错误:\r”,
"",
“活动ID:a3a04a88-7112-466b-99d9-9cf9413edd4a”,
“例外类型:GraphSyntaxException”,
“例外消息:\r”,
“\tGremlin查询语法错误:不支持的groovy语言规则:'parExpression'text:'('username'@第1行,第40列。\r”,
“\t1错误”,
“来源:Microsoft.Azure.Cosmos.Gremlin.Core”,
“\tGremlinRequestId:a3a04a88-7112-466b-99d9-9cf9413edd4a”,
“\t上下文:graphcompute”,
“\t作用域:graphparse translate outer”,
“\tGraphInterOpStatusCode:QuerySyntaxError”,
“\tHResult:0x80131500\r”,
" (597)",
“at Connection._handleMessage(/opt/nodejs/node_modules/gremlin/lib/driver/Connection.js:289:9)”,
在WebSocket上。并抛出错误,但在上面的代码中从未调用我的捕获
备注:-以上代码在AWS lambda中运行未处理的异常与Gremlin库无关,而是我解析Gremlin响应的代码。我错误地解析了submit函数响应,导致代码因未处理的异常而崩溃