Skip to content

Commit 622f52d

Browse files
committed
fix: cache loading approach, add try/catch
1 parent d98ef76 commit 622f52d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lib/api/fetchGitHistory.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@ export const fetchAndCacheGitContributors = async (mdDir: string) => {
5353
const filepath = join("/", mdDir, "index.md")
5454

5555
// Load cache
56-
const commitHistory = fs.existsSync(GIT_CONTRIBUTOR_CACHE_JSON)
57-
? JSON.parse(fs.readFileSync(GIT_CONTRIBUTOR_CACHE_JSON, "utf8"))
58-
: {}
56+
let commitHistory = {}
57+
if (fs.existsSync(GIT_CONTRIBUTOR_CACHE_JSON)) {
58+
try {
59+
commitHistory = JSON.parse(
60+
fs.readFileSync(GIT_CONTRIBUTOR_CACHE_JSON, "utf8")
61+
)
62+
} catch (error) {
63+
console.error(
64+
`Error reading commit history cache for filepath ${filepath}`,
65+
error
66+
)
67+
}
68+
}
5969

6070
// First, check cache for existing commit history for English version (despite locale)
6171
if (commitHistory[filepath]) return commitHistory[filepath]

0 commit comments

Comments
 (0)