Log swallowed errors in debug mode

This commit is contained in:
Daniel Huigens 2018-04-11 13:42:06 +02:00
parent 7c3bbe9278
commit 5d43b44e50
4 changed files with 20 additions and 3 deletions

View File

@ -157,7 +157,9 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) {
try { try {
await keyPacket.decrypt(password); await keyPacket.decrypt(password);
keyPackets.push(keyPacket); keyPackets.push(keyPacket);
} catch (err) {} } catch (err) {
util.print_debug_error(err);
}
})); }));
})); }));
} else if (privateKeys) { } else if (privateKeys) {
@ -180,7 +182,9 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) {
try { try {
await keyPacket.decrypt(privateKeyPacket); await keyPacket.decrypt(privateKeyPacket);
keyPackets.push(keyPacket); keyPackets.push(keyPacket);
} catch (err) {} } catch (err) {
util.print_debug_error(err);
}
})); }));
})); }));
} else { } else {

View File

@ -568,7 +568,7 @@ function parseMessage(message, format) {
*/ */
function onError(message, error) { function onError(message, error) {
// log the stack trace // log the stack trace
if (config.debug) { console.error(error.stack); } util.print_debug_error(error);
// update error message // update error message
error.message = message + ': ' + error.message; error.message = message + ': ' + error.message;

View File

@ -54,6 +54,7 @@ List.prototype.read = function (bytes) {
parsed.tag === enums.packet.compressed) { parsed.tag === enums.packet.compressed) {
throw e; throw e;
} }
util.print_debug_error(e);
if (pushed) { if (pushed) {
this.pop(); // drop unsupported packet this.pop(); // drop unsupported packet
} }

View File

@ -376,6 +376,18 @@ export default {
} }
}, },
/**
* Helper function to print a debug error. Debug
* messages are only printed if
* @link module:config/config.debug is set to true.
* @param {String} str String of the debug message
*/
print_debug_error: function (error) {
if (config.debug) {
console.error(error);
}
},
// TODO rewrite getLeftNBits to work with Uint8Arrays // TODO rewrite getLeftNBits to work with Uint8Arrays
getLeftNBits: function (string, bitcount) { getLeftNBits: function (string, bitcount) {
const rest = bitcount % 8; const rest = bitcount % 8;