Better error handling for getSQLKey

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-07-22 16:36:54 -05:00 committed by GitHub
parent deed0175fb
commit 6e90054f8f
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 }> {
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 {
// This should be the first awaited call in this function, otherwise
// `sql.sqlCall` will throw an uninitialized error instead of waiting for
@ -1691,7 +1717,7 @@ async function initializeSQL(
await sql.initialize({
appVersion: app.getVersion(),
configDir: userDataPath,
key: getSQLKey(),
key,
logger: getLogger(),
});
} catch (error: unknown) {