Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e604124

Browse files
committed
fix: tolerant parse error for local options, close #518
1 parent 3c0e282 commit e604124

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/devtools/src/utils/local-options.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearc
1414
const { filePath } = getOptionsFilepath(options)
1515

1616
if (existsSync(filePath)) {
17-
const options = {
18-
...defaults,
19-
...JSON.parse(await fs.readFile(filePath, 'utf-8')).settings || {},
17+
try {
18+
const options = {
19+
...defaults,
20+
...JSON.parse(await fs.readFile(filePath, 'utf-8')).settings || {},
21+
}
22+
return options
23+
}
24+
catch (e) {
25+
console.error(`[DevTools] failed to parse local options file: ${filePath}, fallback to defaults`)
26+
console.error(e)
27+
return { ...defaults }
2028
}
21-
return options
2229
}
2330
else {
2431
return { ...defaults }

0 commit comments

Comments
 (0)