Skip to content

Commit e700a60

Browse files
authored
fix(stage-tamagotchi): check config path existence before read (#644)
1 parent cabb104 commit e700a60

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

apps/stage-tamagotchi/src/main/windows/shared/persistence.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'node:fs'
1+
import { existsSync, readFileSync } from 'node:fs'
22
import { writeFile } from 'node:fs/promises'
33
import { join } from 'node:path'
44

@@ -19,7 +19,10 @@ export function createConfig<T>(namespace: string, filename: string, options?: {
1919
}
2020

2121
function setup() {
22-
const data = parseOrFallback<T>(readFileSync(configPath(), { encoding: 'utf-8' }), options?.default)
22+
const path = configPath()
23+
const data = existsSync(path)
24+
? parseOrFallback<T>(readFileSync(configPath(), { encoding: 'utf-8' }), options?.default)
25+
: options?.default
2326
persistenceMap.set(`${namespace}-${filename}`, data)
2427
}
2528

0 commit comments

Comments
 (0)