Add lint rule for unhandled promise rejections

This commit is contained in:
Zaid Abdulla committed 2020-09-08 17:33:48 -07:00
1 parent ad682d0b69
commit 0b60406b43
14 files changed
+177 -117

No files matched your search

+1
View File
@@ -58,6 +58,7 @@ export function run(args: string[]): Promise<{ fault: Fault; value: any }> {
});
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
kill(processes[scriptName]);
delete processes[scriptName];
}
+3 -3
View File
@@ -299,7 +299,7 @@ export async function transferComplete(
sessionContext.operationsTouched[commandKey] = 1;
if (rpcReq.faultStruct && rpcReq.faultStruct.faultCode !== "0") {
await revertDownloadParameters(sessionContext, operation.args.instance);
revertDownloadParameters(sessionContext, operation.args.instance);
const fault: Fault = {
code: `cwmp.${rpcReq.faultStruct.faultCode}`,
@@ -398,10 +398,10 @@ export async function transferComplete(
};
}
async function revertDownloadParameters(
function revertDownloadParameters(
sessionContext: SessionContext,
instance
): Promise<void> {
): void {
const timestamp = sessionContext.timestamp + sessionContext.iteration + 1;
let p;
+3 -2
View File
@@ -110,7 +110,7 @@ export async function postTasks(
try {
await connectionRequest(deviceId, device);
} catch (err) {
for (const t of statuses) db.deleteTask(new ObjectID(t._id));
await Promise.all(statuses.map((t) => db.deleteTask(new ObjectID(t._id))));
return {
connectionRequest: err.message,
tasks: statuses,
@@ -138,9 +138,10 @@ export async function postTasks(
r.status = "fault";
r["fault"] = res[i * 2 + 1][0];
}
db.deleteTask(new ObjectID(r._id));
}
await Promise.all(statuses.map((t) => db.deleteTask(new ObjectID(t._id))));
return { connectionRequest: "OK", tasks: statuses };
}
+74 -70
View File
@@ -128,78 +128,80 @@ export function query(
}
return new Promise((resolve, reject) => {
getClient().then((client) => {
const collection = client
.db()
.collection(RESOURCE_COLLECTION[resource] || resource);
const cursor = collection.find(q);
if (options.projection) {
let projection = options.projection;
if (resource === "devices") {
projection = mongodbFunctions.processDeviceProjection(
options.projection
);
getClient()
.then((client) => {
const collection = client
.db()
.collection(RESOURCE_COLLECTION[resource] || resource);
const cursor = collection.find(q);
if (options.projection) {
let projection = options.projection;
if (resource === "devices") {
projection = mongodbFunctions.processDeviceProjection(
options.projection
);
}
if (resource === "presets") projection.configurations = 1;
cursor.project(projection);
}
if (resource === "presets") projection.configurations = 1;
cursor.project(projection);
}
if (resource === "users") cursor.project({ password: 0, salt: 0 });
if (resource === "users") cursor.project({ password: 0, salt: 0 });
if (options.skip) cursor.skip(options.skip);
if (options.limit) cursor.limit(options.limit);
if (options.skip) cursor.skip(options.skip);
if (options.limit) cursor.limit(options.limit);
if (options.sort) {
let s = Object.entries(options.sort)
.sort((a, b) => Math.abs(b[1]) - Math.abs(a[1]))
.reduce(
(obj, [k, v]) =>
Object.assign(obj, { [k]: Math.min(Math.max(v, -1), 1) }),
{}
);
if (options.sort) {
let s = Object.entries(options.sort)
.sort((a, b) => Math.abs(b[1]) - Math.abs(a[1]))
.reduce(
(obj, [k, v]) =>
Object.assign(obj, { [k]: Math.min(Math.max(v, -1), 1) }),
{}
);
if (resource === "devices") s = mongodbFunctions.processDeviceSort(s);
cursor.sort(s);
}
if (resource === "devices") s = mongodbFunctions.processDeviceSort(s);
cursor.sort(s);
}
if (!callback) {
cursor.toArray((err, docs) => {
if (err) return reject(err);
if (resource === "devices")
docs = docs.map((d) => mongodbFunctions.flattenDevice(d));
else if (resource === "faults")
docs = docs.map((d) => mongodbFunctions.flattenFault(d));
else if (resource === "tasks")
docs = docs.map((d) => mongodbFunctions.flattenTask(d));
else if (resource === "presets")
docs = docs.map((d) => mongodbFunctions.flattenPreset(d));
else if (resource === "files")
docs = docs.map((d) => mongodbFunctions.flattenFile(d));
return resolve(docs);
});
} else {
cursor.forEach(
(doc) => {
if (!callback) {
cursor.toArray((err, docs) => {
if (err) return reject(err);
if (resource === "devices")
doc = mongodbFunctions.flattenDevice(doc);
docs = docs.map((d) => mongodbFunctions.flattenDevice(d));
else if (resource === "faults")
doc = mongodbFunctions.flattenFault(doc);
docs = docs.map((d) => mongodbFunctions.flattenFault(d));
else if (resource === "tasks")
doc = mongodbFunctions.flattenTask(doc);
docs = docs.map((d) => mongodbFunctions.flattenTask(d));
else if (resource === "presets")
doc = mongodbFunctions.flattenPreset(doc);
docs = docs.map((d) => mongodbFunctions.flattenPreset(d));
else if (resource === "files")
doc = mongodbFunctions.flattenFile(doc);
callback(doc);
},
(err) => {
if (err) reject(err);
else resolve();
}
);
}
});
docs = docs.map((d) => mongodbFunctions.flattenFile(d));
return resolve(docs);
});
} else {
cursor.forEach(
(doc) => {
if (resource === "devices")
doc = mongodbFunctions.flattenDevice(doc);
else if (resource === "faults")
doc = mongodbFunctions.flattenFault(doc);
else if (resource === "tasks")
doc = mongodbFunctions.flattenTask(doc);
else if (resource === "presets")
doc = mongodbFunctions.flattenPreset(doc);
else if (resource === "files")
doc = mongodbFunctions.flattenFile(doc);
callback(doc);
},
(err) => {
if (err) reject(err);
else resolve();
}
);
}
})
.catch(reject);
});
}
@@ -221,15 +223,17 @@ export function count(resource: string, filter: Expression): Promise<number> {
}
return new Promise((resolve, reject) => {
getClient().then((client) => {
const collection = client
.db()
.collection(RESOURCE_COLLECTION[resource] || resource);
collection.find(q).count((err, c) => {
if (err) reject(err);
else resolve(c);
});
});
getClient()
.then((client) => {
const collection = client
.db()
.collection(RESOURCE_COLLECTION[resource] || resource);
collection.find(q).count((err, c) => {
if (err) reject(err);
else resolve(c);
});
})
.catch(reject);
});
}