mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3447 from Steve-Mcl/fix-hook-module-location
Improve module location parsing (of stack info) when adding hook
This commit is contained in:
commit
263e68e677
@ -67,8 +67,25 @@ function add(hookId, callback) {
|
||||
throw new Error("Hook "+hookId+" already registered")
|
||||
}
|
||||
// Get location of calling code
|
||||
let callModule;
|
||||
const stack = new Error().stack;
|
||||
const callModule = stack.split("\n")[2].split("(")[1].slice(0,-1);
|
||||
const stackEntries = stack.split("\n").slice(1);//drop 1st line (error message)
|
||||
const stackEntry2 = stackEntries[1];//get 2nd stack entry
|
||||
if (stackEntry2) {
|
||||
try {
|
||||
if (stackEntry2.indexOf(" (") >= 0) {
|
||||
callModule = stackEntry2.split("(")[1].slice(0, -1);
|
||||
} else {
|
||||
callModule = stackEntry2.split(" ").slice(-1)[0];
|
||||
}
|
||||
} catch (error) {
|
||||
Log.debug(`Unable to determined module when adding hook '${hookId}'. Stack:\n${stackEntries.join("\n")}`);
|
||||
callModule = "unknown:0:0";
|
||||
}
|
||||
} else {
|
||||
Log.debug(`Unable to determined module when adding hook '${hookId}'. Stack:\n${stackEntries.join("\n")}`);
|
||||
callModule = "unknown:0:0";
|
||||
}
|
||||
Log.debug(`Adding hook '${hookId}' from ${callModule}`);
|
||||
|
||||
const hookItem = {cb:callback, location: callModule, previousHook: null, nextHook: null }
|
||||
|
Loading…
Reference in New Issue
Block a user