1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3346 from node-red/fix-stack-capture

Handle reporting error location when stack is truncated
This commit is contained in:
Nick O'Leary 2022-01-12 22:54:25 +00:00 committed by GitHub
commit 20dbf7c5f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -32,8 +32,14 @@ function wrapEventFunction(obj,func) {
return function(eventName, listener) { return function(eventName, listener) {
if (deprecatedEvents.hasOwnProperty(eventName)) { if (deprecatedEvents.hasOwnProperty(eventName)) {
const log = require("@node-red/util").log; 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) return events["_"+func].call(events,eventName,listener)
} }