From 5d43b44e50cca738d7de97c2a41fa1ce9ebdd8af Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Wed, 11 Apr 2018 13:42:06 +0200 Subject: [PATCH] Log swallowed errors in debug mode --- src/message.js | 8 ++++++-- src/openpgp.js | 2 +- src/packet/packetlist.js | 1 + src/util.js | 12 ++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/message.js b/src/message.js index 76f58c4b..f0e1211f 100644 --- a/src/message.js +++ b/src/message.js @@ -157,7 +157,9 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) { try { await keyPacket.decrypt(password); keyPackets.push(keyPacket); - } catch (err) {} + } catch (err) { + util.print_debug_error(err); + } })); })); } else if (privateKeys) { @@ -180,7 +182,9 @@ Message.prototype.decryptSessionKeys = async function(privateKeys, passwords) { try { await keyPacket.decrypt(privateKeyPacket); keyPackets.push(keyPacket); - } catch (err) {} + } catch (err) { + util.print_debug_error(err); + } })); })); } else { diff --git a/src/openpgp.js b/src/openpgp.js index 612d05c2..4b32fdf0 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -568,7 +568,7 @@ function parseMessage(message, format) { */ function onError(message, error) { // log the stack trace - if (config.debug) { console.error(error.stack); } + util.print_debug_error(error); // update error message error.message = message + ': ' + error.message; diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index 3392825a..0631cd0d 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -54,6 +54,7 @@ List.prototype.read = function (bytes) { parsed.tag === enums.packet.compressed) { throw e; } + util.print_debug_error(e); if (pushed) { this.pop(); // drop unsupported packet } diff --git a/src/util.js b/src/util.js index a9afee83..cd3bf2d1 100644 --- a/src/util.js +++ b/src/util.js @@ -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 getLeftNBits: function (string, bitcount) { const rest = bitcount % 8;