Better error handling for getSQLKey
This commit is contained in:
parent
9006990e58
commit
3b9de8f549
1 changed files with 27 additions and 1 deletions
28
app/main.ts
28
app/main.ts
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue