diff --git a/preload.js b/preload.js index 801364155..72dd8a78a 100644 --- a/preload.js +++ b/preload.js @@ -64,7 +64,11 @@ window.setPassword = async (passPhrase, oldPhrase) => new Promise((resolve, reject) => { ipc.once('set-password-response', (_event, response) => { if (!response) { - return reject('window.setPassword: No response from main process'); + // We don't reject here, but return undefined and handle the result in the caller. + // The reason is because we sometimes want to reject, but sometimes not depending on what the caller is doing (set/change/remove) + // For instance, removing a password makes `!response` true, and so we would reject here even if we + // technically didn't have an reason to. + return resolve(undefined); } return resolve(response); }); diff --git a/ts/components/dialog/SessionSetPasswordDialog.tsx b/ts/components/dialog/SessionSetPasswordDialog.tsx index f35466916..e032f9a89 100644 --- a/ts/components/dialog/SessionSetPasswordDialog.tsx +++ b/ts/components/dialog/SessionSetPasswordDialog.tsx @@ -195,6 +195,9 @@ export class SessionSetPasswordDialog extends Component { } try { const updatedHash = await window.setPassword(enteredPassword, null); + if (!updatedHash) { + throw new Error('window.setPassword expected updatedHash to be set for actionSet'); + } await Storage.put('passHash', updatedHash); ToastUtils.pushToastSuccess( @@ -245,6 +248,9 @@ export class SessionSetPasswordDialog extends Component { try { const updatedHash = await window.setPassword(newPassword, oldPassword); + if (!updatedHash) { + throw new Error('window.setPassword expected updatedHash to be set for actionChange'); + } await Storage.put('passHash', updatedHash); ToastUtils.pushToastSuccess( @@ -276,7 +282,10 @@ export class SessionSetPasswordDialog extends Component { } try { - await window.setPassword(null, oldPassword); + const updatedHash = await window.setPassword(null, oldPassword); + if (updatedHash) { + throw new Error('window.setPassword expected updatedHash to be unset for actionRemove'); + } await Storage.remove('passHash'); ToastUtils.pushToastWarning( diff --git a/ts/session/utils/job_runners/PersistedJob.ts b/ts/session/utils/job_runners/PersistedJob.ts index 0ad07b98a..022ce461f 100644 --- a/ts/session/utils/job_runners/PersistedJob.ts +++ b/ts/session/utils/job_runners/PersistedJob.ts @@ -116,7 +116,7 @@ export abstract class PersistedJob { }) .catch(e => { window.log.warn( - 'runJob() threw. this cannot happen, but rehtrowing as this should be handled in each jobs run()', + 'runJob() threw. this cannot happen, but rethrowing as this should be handled in each jobs run()', e ); throw e; diff --git a/ts/window.d.ts b/ts/window.d.ts index 9d3eef2af..158b4fe16 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -47,7 +47,7 @@ declare global { persistStore?: Persistor; restart: () => void; getSeedNodeList: () => Array | undefined; - setPassword: (newPassword: string | null, oldPassword: string | null) => Promise; + setPassword: (newPassword: string | null, oldPassword: string | null) => Promise; isOnline: boolean; toggleMediaPermissions: () => Promise; toggleCallMediaPermissionsTo: (enabled: boolean) => Promise;