diff --git a/.changeset/fair-berries-study.md b/.changeset/fair-berries-study.md new file mode 100644 index 000000000..fadde388e --- /dev/null +++ b/.changeset/fair-berries-study.md @@ -0,0 +1,5 @@ +--- +'@astrojs/telemetry': patch +--- + +Wrap `JSON.parse` in `try`/`catch` diff --git a/packages/telemetry/src/config.ts b/packages/telemetry/src/config.ts index f0d855597..6efcb7fe5 100644 --- a/packages/telemetry/src/config.ts +++ b/packages/telemetry/src/config.ts @@ -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) { this._store = value;