Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/lib/db/dsn-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>;
let dirMtimes: Record<string, number>;
let allDsns: DetectedDsn[];
try {
sourceMtimes = JSON.parse(row.source_mtimes_json) as Record<string, number>;
dirMtimes = row.dir_mtimes_json
? (JSON.parse(row.dir_mtimes_json) as Record<string, number>)
: {};
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<string, number>)
: {};
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,
Expand Down
10 changes: 9 additions & 1 deletion src/lib/db/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/sentry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ async function handleUnauthorized(headers: Headers): Promise<boolean> {
headers.set(RETRY_MARKER_HEADER, "1");
return true;
}
} catch {
// Token refresh failed
} catch (error) {
log.debug("Token refresh failed after 401", error);
}
return false;
}
Expand Down Expand Up @@ -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);
});
}

Expand All @@ -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);
}
}

Expand Down
Loading