diff --git a/src/lib/db/dsn-cache.ts b/src/lib/db/dsn-cache.ts index 2dddd478c..c54943b81 100644 --- a/src/lib/db/dsn-cache.ts +++ b/src/lib/db/dsn-cache.ts @@ -362,32 +362,33 @@ export async function getCachedDetection( return; } - // Parse source mtimes and validate - const sourceMtimes = JSON.parse(row.source_mtimes_json) as Record< - string, - number - >; + let sourceMtimes: Record; + let dirMtimes: Record; + let allDsns: DetectedDsn[]; + try { + sourceMtimes = JSON.parse(row.source_mtimes_json) as Record; + dirMtimes = row.dir_mtimes_json + ? (JSON.parse(row.dir_mtimes_json) as Record) + : {}; + allDsns = JSON.parse(row.all_dsns_json) as DetectedDsn[]; + } catch { + recordCacheHit("dsn-detection", false); + return; + } + if (!(await validateSourceMtimes(projectRoot, sourceMtimes))) { recordCacheHit("dsn-detection", false); return; } - // Parse directory mtimes and validate (if present) - const dirMtimes = row.dir_mtimes_json - ? (JSON.parse(row.dir_mtimes_json) as Record) - : {}; if (!(await validateDirMtimes(projectRoot, dirMtimes))) { recordCacheHit("dsn-detection", false); return; } recordCacheHit("dsn-detection", true); - // Cache is valid - update last access time touchCacheEntry("dsn_cache", "directory", projectRoot); - // Parse and return cached detection - const allDsns = JSON.parse(row.all_dsns_json) as DetectedDsn[]; - return { fingerprint: row.fingerprint, allDsns, diff --git a/src/lib/db/pagination.ts b/src/lib/db/pagination.ts index c702918d9..c51029fd7 100644 --- a/src/lib/db/pagination.ts +++ b/src/lib/db/pagination.ts @@ -84,7 +84,15 @@ export function getPaginationState( return; } - const stack = JSON.parse(row.cursor_stack) as string[]; + let stack: string[]; + try { + stack = JSON.parse(row.cursor_stack) as string[]; + } catch { + db.query( + "DELETE FROM pagination_cursors WHERE command_key = ? AND context = ?" + ).run(commandKey, contextKey); + return; + } return { stack, index: row.page_index }; } diff --git a/src/lib/sentry-client.ts b/src/lib/sentry-client.ts index c09bf48e5..cb26752a5 100644 --- a/src/lib/sentry-client.ts +++ b/src/lib/sentry-client.ts @@ -187,8 +187,8 @@ async function handleUnauthorized(headers: Headers): Promise { headers.set(RETRY_MARKER_HEADER, "1"); return true; } - } catch { - // Token refresh failed + } catch (error) { + log.debug("Token refresh failed after 401", error); } return false; } @@ -419,8 +419,8 @@ function cacheResponse( fullUrl, requestHeaders, response.clone() as Response - ).catch(() => { - // Non-fatal: cache write failures don't affect the response + ).catch((error) => { + log.debug("Response cache write failed", error); }); } @@ -447,8 +447,8 @@ async function invalidateAfterMutation( await Promise.all( prefixes.map((prefix) => invalidateCachedResponsesMatching(prefix)) ); - } catch { - /* best-effort: mutation already succeeded upstream */ + } catch (error) { + log.debug("Post-mutation cache invalidation failed", error); } }