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;
|
if (this._store) return this._store;
|
||||||
this.ensureDir();
|
this.ensureDir();
|
||||||
if (fs.existsSync(this.file)) {
|
if (fs.existsSync(this.file)) {
|
||||||
|
try {
|
||||||
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
||||||
} else {
|
} catch {}
|
||||||
const store = {};
|
}
|
||||||
this._store = store;
|
if (!this._store) {
|
||||||
|
this._store = {};
|
||||||
this.write();
|
this.write();
|
||||||
}
|
}
|
||||||
return this._store!;
|
return this._store;
|
||||||
}
|
}
|
||||||
private set store(value: Record<string, any>) {
|
private set store(value: Record<string, any>) {
|
||||||
this._store = value;
|
this._store = value;
|
||||||
|
|
Loading…
Reference in a new issue