1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Cli: Fixes #4000: Display proper error message when decryption worker cannot be started

This commit is contained in:
Laurent Cozic 2020-10-29 23:37:19 +00:00
parent 8cfe4b0f82
commit 86c471afcd
2 changed files with 9 additions and 5 deletions

View File

@ -45,10 +45,12 @@ class Command extends BaseCommand {
const startDecryption = async () => {
this.stdout(_('Starting decryption... Please wait as it may take several minutes depending on how much there is to decrypt.'));
while (true) {
try {
const result = await DecryptionWorker.instance().start();
if (result.error) throw result.error;
const line = [];
line.push(_('Decrypted items: %d', result.decryptedItemCount));
if (result.skippedItemCount) line.push(_('Skipped items: %d (use --retry-failed-items to retry decrypting them)', result.skippedItemCount));

View File

@ -106,8 +106,9 @@ class DecryptionWorker {
if (!('errorHandler' in options)) options.errorHandler = 'log';
if (this.state_ !== 'idle') {
this.logger().debug(`DecryptionWorker: cannot start because state is "${this.state_}"`);
return;
const msg = `DecryptionWorker: cannot start because state is "${this.state_}"`;
this.logger().debug(msg);
return { error: new Error(msg) };
}
// Note: the logic below is an optimisation to avoid going through the loop if no master key exists
@ -115,7 +116,8 @@ class DecryptionWorker {
// "throw" and "dispatch" logic.
const loadedMasterKeyCount = await this.encryptionService().loadedMasterKeysCount();
if (!loadedMasterKeyCount) {
this.logger().info('DecryptionWorker: cannot start because no master key is currently loaded.');
const msg = 'DecryptionWorker: cannot start because no master key is currently loaded.';
this.logger().info(msg);
const ids = await MasterKey.allIds();
if (ids.length) {
@ -130,7 +132,7 @@ class DecryptionWorker {
});
}
}
return;
return { error: new Error(msg) };
}
this.logger().info('DecryptionWorker: starting decryption...');