Skip to content

Commit

Permalink
fix: prevent cache corruption from causing persistent crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Jun 8, 2023
1 parent 1be1cff commit dab6b41
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions core/src/detect-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ export function detectComponents(
.replace(/\\/g, "/")
)
);
let existingCache: CachedProjectComponents = fs.existsSync(cacheFilePath)
? (JSON.parse(
let existingCache: CachedProjectComponents = {
detectionStartTimestamp: 0,
components: [],
};
if (fs.existsSync(cacheFilePath)) {
try {
existingCache = JSON.parse(
fs.readFileSync(cacheFilePath, "utf8")
) as CachedProjectComponents)
: {
detectionStartTimestamp: 0,
components: [],
};
) as CachedProjectComponents;
} catch (e) {
logger.warn(`Unable to parse JSON from cache at ${cacheFilePath}`);
}
}
if (
existingCache.detectionStartTimestamp <
(await detectionMinimalTimestamp(workspace.rootDirPath))
Expand Down

0 comments on commit dab6b41

Please sign in to comment.