Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): Silently swallow errors when reading/writing Store #1268

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/utils/src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ export class Store<T> {
*/
public get(): T {
if (this.data === undefined) {
this.data = existsSync(this.path)
? (JSON.parse(readFileSync(this.path, 'utf8')) as T)
: this.initial;
try {
this.data = existsSync(this.path)
? (JSON.parse(readFileSync(this.path, 'utf8')) as T)
: this.initial;
} catch (e) {
this.data = this.initial;
}
}

return this.data;
Expand All @@ -76,8 +80,11 @@ export class Store<T> {

/** Serializes the current data into the JSON file. */
private flush(): void {
mkdirpSync(dirname(this.path));
writeFileSync(this.path, JSON.stringify(this.data));
this.flushing = false;
try {
mkdirpSync(dirname(this.path));
writeFileSync(this.path, JSON.stringify(this.data));
} finally {
this.flushing = false;
}
}
}