From 3152c4f2aa237dd51d1edf3d104aacfa2f64b049 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 5 Apr 2025 14:11:46 -0500 Subject: [PATCH] Augment sql logging --- src/app/static.ts | 2 +- src/photo/db/query.ts | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/static.ts b/src/app/static.ts index 3fad0f6d..0235691b 100644 --- a/src/app/static.ts +++ b/src/app/static.ts @@ -14,7 +14,7 @@ type StaticOutput = 'page' | 'image'; const logStaticGenerationDetails = (count: number, content: string) => { const label = pluralize(count, content, undefined, 3); - console.log(`Statically generating ${label} ...`); + console.log(`> Statically generating ${label} ...`); }; export const staticallyGeneratePhotosIfConfigured = (type: StaticOutput) => diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index 9cdd6fb5..376a58d7 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -65,8 +65,8 @@ const createPhotosTable = () => ) `; -// Safe wrapper for most queries with JIT table creation/migration -// Catch up to 3 migrations in older installations +// Safe wrapper intended for most queries with JIT migration/table creation +// Catches up to 3 migrations in older installations const safelyQueryPhotos = async ( callback: () => Promise, queryLabel: string, @@ -115,19 +115,25 @@ const safelyQueryPhotos = async ( await createPhotosTable(); result = await callback(); } else if (/endpoint is in transition/i.test(e.message)) { - console.log('sql get error: endpoint is in transition (setting timeout)'); + console.log( + 'SQL query error: endpoint is in transition (setting timeout)', + ); // Wait 5 seconds and try again await new Promise(resolve => setTimeout(resolve, 5000)); try { result = await callback(); } catch (e: any) { - console.log(`sql get error on retry (after 5000ms): ${e.message}`); + console.log( + `SQL query error on retry (after 5000ms): ${e.message}`, + ); throw e; } } else { + // Avoid re-logging errors on initial installation if (e.message !== 'The server does not support SSL connections') { - // Avoid re-logging errors on initial installation - console.log(`sql get error (${queryLabel}): ${e.message}`); + console.log(`SQL query error (${queryLabel}): ${e.message}`, { + error: e, + }); } throw e; }