Wrap JSON.parse
in try
/catch
(#8363)
* fix(telemetry): wrap JSON.parse in try/catch * fix: always write the store * chore(lint): fix
This commit is contained in:
parent
7a91600a9e
commit
0ce0720c7f
2 changed files with 12 additions and 5 deletions
5
.changeset/fair-berries-study.md
Normal file
5
.changeset/fair-berries-study.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/telemetry': patch
|
||||
---
|
||||
|
||||
Wrap `JSON.parse` in `try`/`catch`
|
|
@ -46,13 +46,15 @@ export class GlobalConfig {
|
|||
if (this._store) return this._store;
|
||||
this.ensureDir();
|
||||
if (fs.existsSync(this.file)) {
|
||||
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
||||
} else {
|
||||
const store = {};
|
||||
this._store = store;
|
||||
try {
|
||||
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
||||
} catch {}
|
||||
}
|
||||
if (!this._store) {
|
||||
this._store = {};
|
||||
this.write();
|
||||
}
|
||||
return this._store!;
|
||||
return this._store;
|
||||
}
|
||||
private set store(value: Record<string, any>) {
|
||||
this._store = value;
|
||||
|
|
Loading…
Reference in a new issue