From a79e4d1bb30bbcec8487d9ccb4e0b8db11c84547 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 14 Jan 2017 21:33:11 +0000 Subject: [PATCH] Node logged errors not displayed properly in debug pane Fixes #1116 --- nodes/core/core/58-debug.js | 11 ++++++++++- nodes/core/core/lib/debug/debug-utils.js | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/nodes/core/core/58-debug.js b/nodes/core/core/58-debug.js index 7d4a9f0f7..c3431bcb1 100644 --- a/nodes/core/core/58-debug.js +++ b/nodes/core/core/58-debug.js @@ -79,7 +79,16 @@ module.exports = function(RED) { function sendDebug(msg) { if (msg.msg instanceof Error) { msg.format = "error"; - msg.msg = msg.msg.toString(); + var errorMsg = {}; + if (msg.msg.name) { + errorMsg.name = msg.msg.name; + } + if (msg.msg.hasOwnProperty('message')) { + errorMsg.message = msg.msg.message; + } else { + errorMsg.message = msg.msg.toString(); + } + msg.msg = JSON.stringify(errorMsg); } else if (msg.msg instanceof Buffer) { msg.format = "buffer["+msg.msg.length+"]"; msg.msg = msg.msg.toString('hex'); diff --git a/nodes/core/core/lib/debug/debug-utils.js b/nodes/core/core/lib/debug/debug-utils.js index 78f1f9856..ad18dab2c 100644 --- a/nodes/core/core/lib/debug/debug-utils.js +++ b/nodes/core/core/lib/debug/debug-utils.js @@ -230,8 +230,11 @@ RED.debug = (function() { (o.property?'msg.'+property:'msg')+" : "+format+ '').appendTo(metaRow); } - if (format === 'Object' || /^array/.test(format) || format === 'boolean' || format === 'number'||/error/i.test(format) ) { + if (format === 'Object' || /^array/.test(format) || format === 'boolean' || format === 'number' ) { payload = JSON.parse(payload); + } else if (/error/i.test(format)) { + payload = JSON.parse(payload); + payload = (payload.name?payload.name+": ":"")+payload.message; } else if (format === 'null') { payload = null; } else if (format === 'undefined') {