add ignore next to catch errors

This commit is contained in:
Michael C
2022-09-25 03:29:31 -04:00
parent 8562dc2240
commit 506b6570f3
17 changed files with 34 additions and 33 deletions

View File

@@ -200,7 +200,7 @@ function setupRoutes(router: Router) {
router.get("/api/generateToken/:type", generateTokenRequest); router.get("/api/generateToken/:type", generateTokenRequest);
router.get("/api/verifyToken", verifyTokenRequest); router.get("/api/verifyToken", verifyTokenRequest);
/* instanbul ignore next */ /* istanbul ignore next */
if (config.postgres?.enabled) { if (config.postgres?.enabled) {
router.get("/database", (req, res) => dumpDatabase(req, res, true)); router.get("/database", (req, res) => dumpDatabase(req, res, true));
router.get("/database.json", (req, res) => dumpDatabase(req, res, false)); router.get("/database.json", (req, res) => dumpDatabase(req, res, false));

View File

@@ -21,7 +21,7 @@ export async function getIsUserVIP(req: Request, res: Response): Promise<Respons
hashedUserID: hashedUserID, hashedUserID: hashedUserID,
vip: vipState, vip: vipState,
}); });
} catch (err) /* instanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -33,7 +33,7 @@ export async function getLockCategories(req: Request, res: Response): Promise<Re
categories, categories,
actionTypes actionTypes
}); });
} catch (err) { } catch (err) /* istanbul ignore next */{
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -27,7 +27,7 @@ export async function getSavedTimeForUser(req: Request, res: Response): Promise<
} else { } else {
return res.sendStatus(404); return res.sendStatus(404);
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(`getSavedTimeForUser ${err}`); Logger.error(`getSavedTimeForUser ${err}`);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -7,7 +7,7 @@ const isValidSegmentUUID = (str: string): boolean => /^([a-f0-9]{64}|[a-f0-9]{8}
async function getSegmentFromDBByUUID(UUID: SegmentUUID): Promise<DBSegment> { async function getSegmentFromDBByUUID(UUID: SegmentUUID): Promise<DBSegment> {
try { try {
return await db.prepare("get", `SELECT * FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); return await db.prepare("get", `SELECT * FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
} catch (err) { } catch (err) /* istanbul ignore next */ {
return null; return null;
} }
} }
@@ -62,7 +62,7 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
//send result //send result
return res.send(DBSegments); return res.send(DBSegments);
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
if (err instanceof SyntaxError) { // catch JSON.parse error if (err instanceof SyntaxError) { // catch JSON.parse error
return res.status(400).send("UUIDs parameter does not match format requirements."); return res.status(400).send("UUIDs parameter does not match format requirements.");
} else return res.sendStatus(500); } else return res.sendStatus(500);

View File

@@ -107,7 +107,7 @@ async function getSegmentsByVideoID(req: Request, videoID: VideoID, categories:
} }
return processedSegments; return processedSegments;
} catch (err) { } catch (err) /* istanbul ignore next */ {
if (err) { if (err) {
Logger.error(err as string); Logger.error(err as string);
return null; return null;
@@ -169,7 +169,7 @@ async function getSegmentsByHash(req: Request, hashedVideoIDPrefix: VideoIDHash,
})); }));
return segments; return segments;
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return null; return null;
} }
@@ -465,7 +465,7 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
//send result //send result
return res.send(segments); return res.send(segments);
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
if (err instanceof SyntaxError) { if (err instanceof SyntaxError) {
return res.status(400).send("Categories parameter does not match format requirements."); return res.status(400).send("Categories parameter does not match format requirements.");
} else return res.sendStatus(500); } else return res.sendStatus(500);

View File

@@ -27,7 +27,7 @@ export async function getStatus(req: Request, res: Response): Promise<Response>
hostname: os.hostname() hostname: os.hostname()
}; };
return value ? res.send(JSON.stringify(statusValues[value])) : res.send(statusValues); return value ? res.send(JSON.stringify(statusValues[value])) : res.send(statusValues);
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -12,7 +12,7 @@ function getFuzzyUserID(userName: string): Promise<{userName: string, userID: Us
try { try {
return db.prepare("all", `SELECT "userName", "userID" FROM "userNames" WHERE "userName" return db.prepare("all", `SELECT "userName", "userID" FROM "userNames" WHERE "userName"
LIKE ? ESCAPE '\\' LIMIT 10`, [userName]); LIKE ? ESCAPE '\\' LIMIT 10`, [userName]);
} catch (err) { } catch (err) /* istanbul ignore next */ {
return null; return null;
} }
} }
@@ -20,7 +20,7 @@ function getFuzzyUserID(userName: string): Promise<{userName: string, userID: Us
function getExactUserID(userName: string): Promise<{userName: string, userID: UserID }[]> { function getExactUserID(userName: string): Promise<{userName: string, userID: UserID }[]> {
try { try {
return db.prepare("all", `SELECT "userName", "userID" from "userNames" WHERE "userName" = ? LIMIT 10`, [userName]); return db.prepare("all", `SELECT "userName", "userID" from "userNames" WHERE "userName" = ? LIMIT 10`, [userName]);
} catch (err) { } catch (err) /* istanbul ignore next */{
return null; return null;
} }
} }
@@ -42,6 +42,7 @@ export async function getUserID(req: Request, res: Response): Promise<Response>
: await getFuzzyUserID(userName); : await getFuzzyUserID(userName);
if (results === undefined || results === null) { if (results === undefined || results === null) {
/* istanbul ignore next */
return res.sendStatus(500); return res.sendStatus(500);
} else if (results.length === 0) { } else if (results.length === 0) {
return res.sendStatus(404); return res.sendStatus(404);

View File

@@ -28,7 +28,7 @@ async function dbGetSubmittedSegmentSummary(userID: HashedUserID): Promise<{ min
segmentCount: 0, segmentCount: 0,
}; };
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
return null; return null;
} }
} }
@@ -37,7 +37,7 @@ async function dbGetIgnoredSegmentCount(userID: HashedUserID): Promise<number> {
try { try {
const row = await db.prepare("get", `SELECT COUNT(*) as "ignoredSegmentCount" FROM "sponsorTimes" WHERE "userID" = ? AND ( "votes" <= -2 OR "shadowHidden" = 1 )`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT COUNT(*) as "ignoredSegmentCount" FROM "sponsorTimes" WHERE "userID" = ? AND ( "votes" <= -2 OR "shadowHidden" = 1 )`, [userID], { useReplica: true });
return row?.ignoredSegmentCount ?? 0; return row?.ignoredSegmentCount ?? 0;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return null; return null;
} }
} }
@@ -46,7 +46,7 @@ async function dbGetUsername(userID: HashedUserID) {
try { try {
const row = await db.prepare("get", `SELECT "userName" FROM "userNames" WHERE "userID" = ?`, [userID]); const row = await db.prepare("get", `SELECT "userName" FROM "userNames" WHERE "userID" = ?`, [userID]);
return row?.userName ?? userID; return row?.userName ?? userID;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return false; return false;
} }
} }
@@ -55,7 +55,7 @@ async function dbGetViewsForUser(userID: HashedUserID) {
try { try {
const row = await db.prepare("get", `SELECT SUM("views") as "viewCount" FROM "sponsorTimes" WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT SUM("views") as "viewCount" FROM "sponsorTimes" WHERE "userID" = ? AND "votes" > -2 AND "shadowHidden" != 1`, [userID], { useReplica: true });
return row?.viewCount ?? 0; return row?.viewCount ?? 0;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return false; return false;
} }
} }
@@ -64,7 +64,7 @@ async function dbGetIgnoredViewsForUser(userID: HashedUserID) {
try { try {
const row = await db.prepare("get", `SELECT SUM("views") as "ignoredViewCount" FROM "sponsorTimes" WHERE "userID" = ? AND ( "votes" <= -2 OR "shadowHidden" = 1 )`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT SUM("views") as "ignoredViewCount" FROM "sponsorTimes" WHERE "userID" = ? AND ( "votes" <= -2 OR "shadowHidden" = 1 )`, [userID], { useReplica: true });
return row?.ignoredViewCount ?? 0; return row?.ignoredViewCount ?? 0;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return false; return false;
} }
} }
@@ -73,7 +73,7 @@ async function dbGetWarningsForUser(userID: HashedUserID): Promise<number> {
try { try {
const row = await db.prepare("get", `SELECT COUNT(*) as total FROM "warnings" WHERE "userID" = ? AND "enabled" = 1`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT COUNT(*) as total FROM "warnings" WHERE "userID" = ? AND "enabled" = 1`, [userID], { useReplica: true });
return row?.total ?? 0; return row?.total ?? 0;
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(`Couldn't get warnings for user ${userID}. returning 0`); Logger.error(`Couldn't get warnings for user ${userID}. returning 0`);
return 0; return 0;
} }
@@ -83,7 +83,7 @@ async function dbGetLastSegmentForUser(userID: HashedUserID): Promise<SegmentUUI
try { try {
const row = await db.prepare("get", `SELECT "UUID" FROM "sponsorTimes" WHERE "userID" = ? ORDER BY "timeSubmitted" DESC LIMIT 1`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT "UUID" FROM "sponsorTimes" WHERE "userID" = ? ORDER BY "timeSubmitted" DESC LIMIT 1`, [userID], { useReplica: true });
return row?.UUID ?? null; return row?.UUID ?? null;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return null; return null;
} }
} }
@@ -92,7 +92,7 @@ async function dbGetActiveWarningReasonForUser(userID: HashedUserID): Promise<st
try { try {
const row = await db.prepare("get", `SELECT reason FROM "warnings" WHERE "userID" = ? AND "enabled" = 1 ORDER BY "issueTime" DESC LIMIT 1`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT reason FROM "warnings" WHERE "userID" = ? AND "enabled" = 1 ORDER BY "issueTime" DESC LIMIT 1`, [userID], { useReplica: true });
return row?.reason ?? ""; return row?.reason ?? "";
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(`Couldn't get reason for user ${userID}. returning blank`); Logger.error(`Couldn't get reason for user ${userID}. returning blank`);
return ""; return "";
} }
@@ -102,7 +102,7 @@ async function dbGetBanned(userID: HashedUserID): Promise<boolean> {
try { try {
const row = await db.prepare("get", `SELECT count(*) as "userCount" FROM "shadowBannedUsers" WHERE "userID" = ? LIMIT 1`, [userID], { useReplica: true }); const row = await db.prepare("get", `SELECT count(*) as "userCount" FROM "shadowBannedUsers" WHERE "userID" = ? LIMIT 1`, [userID], { useReplica: true });
return row?.userCount > 0 ?? false; return row?.userCount > 0 ?? false;
} catch (err) { } catch (err) /* istanbul ignore next */ {
return false; return false;
} }
} }
@@ -195,7 +195,7 @@ async function getUserInfo(req: Request, res: Response): Promise<Response> {
export async function endpoint(req: Request, res: Response): Promise<Response> { export async function endpoint(req: Request, res: Response): Promise<Response> {
try { try {
return await getUserInfo(req, res); return await getUserInfo(req, res);
} catch (err) { } catch (err) /* istanbul ignore next */ {
if (err instanceof SyntaxError) { // catch JSON.parse error if (err instanceof SyntaxError) { // catch JSON.parse error
return res.status(400).send("Invalid values JSON"); return res.status(400).send("Invalid values JSON");
} else return res.sendStatus(500); } else return res.sendStatus(500);

View File

@@ -71,7 +71,7 @@ async function dbGetUserSummary(userID: HashedUserID, fetchCategoryStats: boolea
}; };
} }
return result; return result;
} catch (err) /* instanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return null; return null;
} }
@@ -81,7 +81,7 @@ async function dbGetUsername(userID: HashedUserID) {
try { try {
const row = await db.prepare("get", `SELECT "userName" FROM "userNames" WHERE "userID" = ?`, [userID]); const row = await db.prepare("get", `SELECT "userName" FROM "userNames" WHERE "userID" = ?`, [userID]);
return row?.userName ?? userID; return row?.userName ?? userID;
} catch (err) /* instanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
return false; return false;
} }
} }

View File

@@ -27,7 +27,7 @@ export async function getUsername(req: Request, res: Response): Promise<Response
userName: userID, userName: userID,
}); });
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -25,7 +25,7 @@ export async function getViewsForUser(req: Request, res: Response): Promise<Resp
} else { } else {
return res.sendStatus(404); return res.sendStatus(404);
} }
} catch (err) /* instanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -47,7 +47,7 @@ export async function postClearCache(req: Request, res: Response): Promise<Respo
return res.status(200).json({ return res.status(200).json({
message: `Cache cleared on video ${videoID}` message: `Cache cleared on video ${videoID}`
}); });
} catch(err) { } catch(err) /* istanbul ignore next */ {
return res.sendStatus(500); return res.sendStatus(500);
} }
} }

View File

@@ -66,7 +66,7 @@ export async function postLockCategories(req: Request, res: Response): Promise<s
for (const lock of locksToApply) { for (const lock of locksToApply) {
try { try {
await db.prepare("run", `INSERT INTO "lockCategories" ("videoID", "userID", "actionType", "category", "hashedVideoID", "reason", "service") VALUES(?, ?, ?, ?, ?, ?, ?)`, [videoID, userID, lock.actionType, lock.category, hashedVideoID, reason, service]); await db.prepare("run", `INSERT INTO "lockCategories" ("videoID", "userID", "actionType", "category", "hashedVideoID", "reason", "service") VALUES(?, ?, ?, ?, ?, ?, ?)`, [videoID, userID, lock.actionType, lock.category, hashedVideoID, reason, service]);
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(`Error submitting 'lockCategories' marker for category '${lock.category}' and actionType '${lock.actionType}' for video '${videoID}' (${service})`); Logger.error(`Error submitting 'lockCategories' marker for category '${lock.category}' and actionType '${lock.actionType}' for video '${videoID}' (${service})`);
Logger.error(err as string); Logger.error(err as string);
res.status(500).json({ res.status(500).json({
@@ -82,7 +82,7 @@ export async function postLockCategories(req: Request, res: Response): Promise<s
await db.prepare("run", await db.prepare("run",
'UPDATE "lockCategories" SET "reason" = ?, "userID" = ? WHERE "videoID" = ? AND "actionType" = ? AND "category" = ? AND "service" = ?', 'UPDATE "lockCategories" SET "reason" = ?, "userID" = ? WHERE "videoID" = ? AND "actionType" = ? AND "category" = ? AND "service" = ?',
[reason, userID, videoID, lock.actionType, lock.category, service]); [reason, userID, videoID, lock.actionType, lock.category, service]);
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(`Error submitting 'lockCategories' marker for category '${lock.category}' and actionType '${lock.actionType}' for video '${videoID}' (${service})`); Logger.error(`Error submitting 'lockCategories' marker for category '${lock.category}' and actionType '${lock.actionType}' for video '${videoID}' (${service})`);
Logger.error(err as string); Logger.error(err as string);
res.status(500).json({ res.status(500).json({

View File

@@ -37,7 +37,7 @@ export async function postPurgeAllSegments(req: Request, res: Response): Promise
service service
}); });
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -91,7 +91,7 @@ export async function postSegmentShift(req: Request, res: Response): Promise<Res
break; break;
} }
} }
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }

View File

@@ -56,7 +56,7 @@ export async function setUsername(req: Request, res: Response): Promise<Response
return res.sendStatus(200); return res.sendStatus(200);
} }
} }
catch (error) { catch (error) /* istanbul ignore next */ {
Logger.error(error as string); Logger.error(error as string);
return res.sendStatus(500); return res.sendStatus(500);
} }
@@ -83,7 +83,7 @@ export async function setUsername(req: Request, res: Response): Promise<Response
await logUserNameChange(userID, userName, oldUserName, adminUserIDInput !== undefined); await logUserNameChange(userID, userName, oldUserName, adminUserIDInput !== undefined);
return res.sendStatus(200); return res.sendStatus(200);
} catch (err) { } catch (err) /* istanbul ignore next */ {
Logger.error(err as string); Logger.error(err as string);
return res.sendStatus(500); return res.sendStatus(500);
} }