From 21f2fadf8536f325f8c85a1c34bce509cb277ba4 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Thu, 29 Aug 2019 22:45:18 +0900 Subject: [PATCH] fix: Remove invalid account cache file when load error --- src/main/cache/account.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/cache/account.ts b/src/main/cache/account.ts index b1c5f674..9f031758 100644 --- a/src/main/cache/account.ts +++ b/src/main/cache/account.ts @@ -1,5 +1,6 @@ import { isEmpty } from 'lodash' import Datastore from 'nedb' +import fs from 'fs' import { CachedAccount } from '~/src/types/cachedAccount' export default class AccountCache { @@ -8,7 +9,16 @@ export default class AccountCache { constructor(path: string) { this.db = new Datastore({ filename: path, - autoload: true + autoload: true, + onload: (err: Error) => { + if (err) { + fs.unlink(path, err => { + if (err) { + console.error(err) + } + }) + } + } }) }