Throw when failed to back up wallet

Co-authored-by: Coolguy3289 <Coolguy3289@users.noreply.github.com>
This commit is contained in:
Snazzah 2021-06-10 17:47:00 -05:00
parent 54d31ef0cc
commit de8169af32
No known key found for this signature in database
GPG key ID: 5E71D54F3D86282E
2 changed files with 13 additions and 5 deletions

View file

@ -21,8 +21,15 @@ module.exports = class DeleteAccount extends Command {
header: header:
`Are you sure you want to delete that account? *(${supportsCount.toLocaleString()} support[s])*` `Are you sure you want to delete that account? *(${supportsCount.toLocaleString()} support[s])*`
})) return; })) return;
await Util.LBRY.deleteAccount(this.client, discordID, account.accountID); try {
return message.channel.createMessage('Deleted account.'); await Util.LBRY.deleteAccount(this.client, discordID, account.accountID);
return message.channel.createMessage('Deleted account.');
} catch (e) {
return message.channel.createMessage(
'Failed to delete the account. An error most likely occured while backing up the wallet.' +
`\n\`\`\`\n${e.toString()}\`\`\``
);
}
} else } else
return message.channel.createMessage('That user does not have an account.'); return message.channel.createMessage('That user does not have an account.');
} }

View file

@ -280,6 +280,7 @@ Util.LBRY = {
} catch (err) { } catch (err) {
console.error('Error occurred while backing up wallet file!'); console.error('Error occurred while backing up wallet file!');
console.error(err); console.error(err);
throw err;
} }
// Abandon supports // Abandon supports
@ -315,7 +316,7 @@ Util.LBRY = {
return { count: supports.length }; return { count: supports.length };
}, },
backupWallet() { backupWallet() {
const wallet = fs.readFileSync(path.join(__dirname, config.walletPath)); const wallet = fs.readFileSync(config.walletPath);
const d = new Date(); const d = new Date();
const date = [ const date = [
d.getUTCFullYear(), d.getUTCFullYear(),
@ -329,7 +330,7 @@ Util.LBRY = {
d.getUTCMilliseconds().toString() d.getUTCMilliseconds().toString()
].join('-'); ].join('-');
const backupName = 'default_wallet.' + date + '_' + time + '.bak'; const backupName = 'default_wallet.' + date + '_' + time + '.bak';
const backupPath = path.join(__dirname, config.walletBackupFolder, backupName); const backupPath = path.join(config.walletBackupFolder, backupName);
fs.writeFileSync(backupPath, wallet); fs.writeFileSync(backupPath, wallet);
console.log(`Backed up wallet file: ${backupPath}`); console.log(`Backed up wallet file: ${backupPath}`);
} }