Refactor cache file reading to check for existence before attempting to read

This commit is contained in:
Mario Campos
2026-06-19 15:41:47 -05:00
parent 126166c212
commit 94b12602ac
2 changed files with 4 additions and 8 deletions

6
lib/entry-points.js generated
View File

@@ -149876,13 +149876,11 @@ function getCommandCacheFilePath() {
return path6.join(getTemporaryDirectory(), COMMAND_CACHE_FILENAME);
}
function readCommandCacheFile() {
let contents;
try {
contents = fs6.readFileSync(getCommandCacheFilePath(), "utf8");
} catch {
if (!fs6.existsSync(getCommandCacheFilePath())) {
return {};
}
try {
const contents = fs6.readFileSync(getCommandCacheFilePath(), "utf8");
const parsed = parseString(contents);
if (isObject(parsed)) {
return parsed;

View File

@@ -47,13 +47,11 @@ function getCommandCacheFilePath(): string {
* or otherwise unreadable file is treated as an empty cache.
*/
function readCommandCacheFile(): Record<string, CommandCacheEntry> {
let contents: string;
try {
contents = fs.readFileSync(getCommandCacheFilePath(), "utf8");
} catch {
if (!fs.existsSync(getCommandCacheFilePath())) {
return {};
}
try {
const contents = fs.readFileSync(getCommandCacheFilePath(), "utf8");
const parsed = json.parseString(contents);
if (json.isObject(parsed)) {
return parsed;