Better error handling for getSQLKey

This commit is contained in:
Fedor Indutny 2024-07-22 12:55:35 -07:00 committed by GitHub
parent 9006990e58
commit 3b9de8f549
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1684,6 +1684,32 @@ async function initializeSQL(
): Promise<{ ok: true; error: undefined } | { ok: false; error: Error }> { ): Promise<{ ok: true; error: undefined } | { ok: false; error: Error }> {
sqlInitTimeStart = Date.now(); sqlInitTimeStart = Date.now();
let key: string;
try {
key = getSQLKey();
} catch (error) {
try {
// Initialize with *some* key to setup paths
await sql.initialize({
appVersion: app.getVersion(),
configDir: userDataPath,
key: 'abcd',
logger: getLogger(),
});
} catch {
// Do nothing, we fail right below anyway.
}
if (error instanceof Error) {
return { ok: false, error };
}
return {
ok: false,
error: new Error(`initializeSQL: Caught a non-error '${error}'`),
};
}
try { try {
// This should be the first awaited call in this function, otherwise // This should be the first awaited call in this function, otherwise
// `sql.sqlRead` will throw an uninitialized error instead of waiting for // `sql.sqlRead` will throw an uninitialized error instead of waiting for
@ -1691,7 +1717,7 @@ async function initializeSQL(
await sql.initialize({ await sql.initialize({
appVersion: app.getVersion(), appVersion: app.getVersion(),
configDir: userDataPath, configDir: userDataPath,
key: getSQLKey(), key,
logger: getLogger(), logger: getLogger(),
}); });
} catch (error: unknown) { } catch (error: unknown) {