Skip to content

Commit

Permalink
fix: tolerant parse error for local options, close #518
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 18, 2023
1 parent 3c0e282 commit e604124
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/devtools/src/utils/local-options.ts
Expand Up @@ -14,11 +14,18 @@ export async function readLocalOptions<T>(defaults: T, options: LocalOptionSearc
const { filePath } = getOptionsFilepath(options)

if (existsSync(filePath)) {
const options = {
...defaults,
...JSON.parse(await fs.readFile(filePath, 'utf-8')).settings || {},
try {
const options = {
...defaults,
...JSON.parse(await fs.readFile(filePath, 'utf-8')).settings || {},
}
return options
}
catch (e) {
console.error(`[DevTools] failed to parse local options file: ${filePath}, fallback to defaults`)
console.error(e)
return { ...defaults }
}
return options
}
else {
return { ...defaults }
Expand Down

0 comments on commit e604124

Please sign in to comment.