From 82ae2e71183319a24e795cb4bd2eaf7a1c670719 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 12 Jan 2022 22:07:44 +0000 Subject: [PATCH] Handle reporting error location when stack is truncated Fixes #3292 --- packages/node_modules/@node-red/util/lib/events.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/util/lib/events.js b/packages/node_modules/@node-red/util/lib/events.js index df45b4d16..b1e1e4f9f 100644 --- a/packages/node_modules/@node-red/util/lib/events.js +++ b/packages/node_modules/@node-red/util/lib/events.js @@ -32,8 +32,14 @@ function wrapEventFunction(obj,func) { return function(eventName, listener) { if (deprecatedEvents.hasOwnProperty(eventName)) { const log = require("@node-red/util").log; - const stack = (new Error().stack).split("\n")[2].split("(")[1].slice(0,-1); - log.warn(`[RED.events] Deprecated use of "${eventName}" event from "${stack}". Use "${deprecatedEvents[eventName]}" instead.`) + + const stack = (new Error().stack).split("\n"); + let location = "(unknown)" + // See https://github.com/node-red/node-red/issues/3292 + if (stack.length > 2) { + location = stack[2].split("(")[1].slice(0,-1); + } + log.warn(`[RED.events] Deprecated use of "${eventName}" event from "${location}". Use "${deprecatedEvents[eventName]}" instead.`) } return events["_"+func].call(events,eventName,listener) }