From 2dcf8630abb51d191eeed187616b2f6e44196ff2 Mon Sep 17 00:00:00 2001 From: Rushil Perera Date: Sun, 27 Oct 2024 08:48:55 -0400 Subject: [PATCH] fix: improve error logging Cloudflare doesn't log causes, only the messages so splitting the logs in to 2 --- src/controllers/auth/anilist/index.ts | 4 ++-- src/controllers/episodes/getByAniListId/anify.ts | 6 ++---- src/controllers/episodes/getByAniListId/aniwatch.ts | 6 ++---- src/controllers/episodes/getByAniListId/consumet.ts | 6 ++---- src/controllers/episodes/markEpisodeAsWatched/anilist.ts | 9 --------- src/controllers/episodes/markEpisodeAsWatched/index.ts | 5 ++--- src/controllers/token/index.ts | 3 ++- src/controllers/watch-status/index.ts | 7 +++---- src/libs/tasks/queueTask.ts | 2 +- 9 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/controllers/auth/anilist/index.ts b/src/controllers/auth/anilist/index.ts index 38d61c0..a6cb83c 100644 --- a/src/controllers/auth/anilist/index.ts +++ b/src/controllers/auth/anilist/index.ts @@ -107,7 +107,7 @@ app.openapi(route, async (c) => { return c.json(ErrorResponse, { status: 401 }); } } catch (error) { - console.error(new Error("Failed to authenticate with AniList")); + console.error("Failed to authenticate with AniList"); console.error(error); return c.json(ErrorResponse, { status: 500 }); } @@ -119,7 +119,7 @@ app.openapi(route, async (c) => { user.name!, ); } catch (error) { - console.error(new Error("Failed to associate device")); + console.error("Failed to associate device"); console.error(error); return c.json(ErrorResponse, { status: 500 }); } diff --git a/src/controllers/episodes/getByAniListId/anify.ts b/src/controllers/episodes/getByAniListId/anify.ts index 349824a..72740ae 100644 --- a/src/controllers/episodes/getByAniListId/anify.ts +++ b/src/controllers/episodes/getByAniListId/anify.ts @@ -46,11 +46,9 @@ export async function getEpisodesFromAnify( abortController.abort("Loading episodes from Anify timed out"); } console.error( - new Error( - `Error trying to load episodes from anify; aniListId: ${aniListId}`, - { cause: e }, - ), + `Error trying to load episodes from anify; aniListId: ${aniListId}`, ); + console.error(e); } if (!response || response.length === 0) { diff --git a/src/controllers/episodes/getByAniListId/aniwatch.ts b/src/controllers/episodes/getByAniListId/aniwatch.ts index f29a2d5..edb32a9 100644 --- a/src/controllers/episodes/getByAniListId/aniwatch.ts +++ b/src/controllers/episodes/getByAniListId/aniwatch.ts @@ -68,11 +68,9 @@ export async function getEpisodesFromAniwatch( } console.error( - new Error( - `Error trying to load episodes from aniwatch; aniListId: ${aniListId}`, - { cause: error }, - ), + `Error trying to load episodes from aniwatch; aniListId: ${aniListId}`, ); + console.error(error); } return null; diff --git a/src/controllers/episodes/getByAniListId/consumet.ts b/src/controllers/episodes/getByAniListId/consumet.ts index 569d8c0..4801295 100644 --- a/src/controllers/episodes/getByAniListId/consumet.ts +++ b/src/controllers/episodes/getByAniListId/consumet.ts @@ -29,11 +29,9 @@ export async function getEpisodesFromConsumet( } catch (error: any) { if (!error.message.includes("failed with status code")) { console.error( - new Error( - `Error trying to load episodes from consumet; aniListId: ${aniListId}`, - { cause: error }, - ), + `Error trying to load episodes from consumet; aniListId: ${aniListId}`, ); + console.error(error); } } diff --git a/src/controllers/episodes/markEpisodeAsWatched/anilist.ts b/src/controllers/episodes/markEpisodeAsWatched/anilist.ts index 1cf55a6..b6da4e8 100644 --- a/src/controllers/episodes/markEpisodeAsWatched/anilist.ts +++ b/src/controllers/episodes/markEpisodeAsWatched/anilist.ts @@ -29,15 +29,6 @@ export async function markEpisodeAsWatched( ) { const client = new GraphQLClient("https://graphql.anilist.co/"); - console.log(aniListToken); - console.log( - typeof aniListToken, - titleId, - typeof titleId, - episodeNumber, - typeof episodeNumber, - markTitleAsComplete, - ); const mutation = markTitleAsComplete ? client.request( MarkTitleAsWatchedMutation, diff --git a/src/controllers/episodes/markEpisodeAsWatched/index.ts b/src/controllers/episodes/markEpisodeAsWatched/index.ts index b1c66ec..91a581a 100644 --- a/src/controllers/episodes/markEpisodeAsWatched/index.ts +++ b/src/controllers/episodes/markEpisodeAsWatched/index.ts @@ -94,9 +94,8 @@ app.openapi(route, async (c) => { ); } } catch (error) { - console.error( - new Error("Failed to mark episode as watched", { cause: error }), - ); + console.error("Failed to mark episode as watched"); + console.error(error); return c.json(ErrorResponse, { status: 500 }); } diff --git a/src/controllers/token/index.ts b/src/controllers/token/index.ts index 645fb7d..adc6953 100644 --- a/src/controllers/token/index.ts +++ b/src/controllers/token/index.ts @@ -78,7 +78,8 @@ app.openapi(route, async (c) => { await saveToken(env(c, "workerd"), deviceId, token); } catch (error) { - console.error(new Error("Failed to save token", { cause: error })); + console.error("Failed to save token"); + console.error(error); return c.json(ErrorResponse, 500); } diff --git a/src/controllers/watch-status/index.ts b/src/controllers/watch-status/index.ts index 27174ca..87a6cab 100644 --- a/src/controllers/watch-status/index.ts +++ b/src/controllers/watch-status/index.ts @@ -105,7 +105,7 @@ app.openapi(route, async (c) => { watchStatus, ); } catch (error) { - console.error(new Error("Error setting watch status", { cause: error })); + console.error("Error setting watch status"); console.error(error); return c.json(ErrorResponse, { status: 500 }); } @@ -118,9 +118,8 @@ app.openapi(route, async (c) => { aniListToken, ); } catch (error) { - console.error( - new Error("Failed to update watch status on Anilist", { cause: error }), - ); + console.error("Failed to update watch status on Anilist"); + console.error(error); if (isRetrying) { return c.json(ErrorResponse, { status: 500 }); } diff --git a/src/libs/tasks/queueTask.ts b/src/libs/tasks/queueTask.ts index 4758c09..0efdd5e 100644 --- a/src/libs/tasks/queueTask.ts +++ b/src/libs/tasks/queueTask.ts @@ -77,7 +77,7 @@ export async function queueTask( .update(task.name.split("/").at(-1)!) .digest("hex"), ); - console.log(hashedTaskName); + console.log("task name", hashedTaskName); const { res } = await queueCloudTask({ ...task, name: