Open
Description
In current puppet-implementation.ts, there are lots of @typescript-eslint/no-misused-promises
problems.
According to https://stackoverflow.com/questions/63488141/promise-returned-in-function-argument-where-a-void-return-was-expected, and handleUnaryCall definition
export type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
The return type for handleUnaryCall should be void
, not Promise<void>
.
So we should change the puppet-implementation methods to this. Take contactAlias as example:
contactAlias: (call, callback) => {
void (async () => {
log.verbose('PuppetServiceImpl', 'contactAlias()')
const id = call.request.getId()
/**
* Set
*/
if (call.request.hasAlias()) {
try {
await puppet.contactAlias(id, call.request.getAlias())
return callback(null, new grpcPuppet.ContactAliasResponse())
} catch (e) {
return grpcError('contactAlias', e, callback)
}
}
/**
* Get
*/
try {
const alias = await puppet.contactAlias(id)
const response = new grpcPuppet.ContactAliasResponse()
response.setAlias(alias)
return callback(null, response)
} catch (e) {
return grpcError('contactAlias', e, callback)
}
})()
},
This ensures that the implicit return of the callback remains undefined, rather than being a promise.
refs:
https://typescript-eslint.io/rules/no-misused-promises/
https://stackoverflow.com/questions/63488141/promise-returned-in-function-argument-where-a-void-return-was-expected
Metadata
Metadata
Assignees
Labels
No labels