diff --git a/app/sql.js b/app/sql.js index 8a60085cc..cf8fb38ac 100644 --- a/app/sql.js +++ b/app/sql.js @@ -679,13 +679,21 @@ async function initialize({ configDir, key }) { // console._log(`EXPLAIN QUERY PLAN ${statement}\n`, data && data.detail); // }); - await setupSQLCipher(promisified, { key }); - await updateSchema(promisified); + try { + await setupSQLCipher(promisified, { key }); + await updateSchema(promisified); + } catch (e) { + await promisified.close(); + throw e; + } db = promisified; } async function close() { + if (!db) { + return; + } const dbRef = db; db = null; await dbRef.close(); diff --git a/main.js b/main.js index 510579edd..5e59c8eca 100644 --- a/main.js +++ b/main.js @@ -751,7 +751,7 @@ function getDefaultSQLKey() { async function removeDB() { const userDir = await getRealPath(app.getPath('userData')); - sql.removeDB(userDir); + await sql.removeDB(userDir); try { userConfig.remove();