Pass full error object in Function node and copy over cause property

Fixes #4683
This commit is contained in:
Nick O'Leary 2024-05-09 16:48:51 +01:00
parent 08927dfb55
commit 66a667fe58
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 11 additions and 7 deletions

View File

@ -438,10 +438,9 @@ module.exports = function(RED) {
//store the error in msg to be used in flows
msg.error = err;
var line = 0;
var errorMessage;
if (stack.length > 0) {
let line = 0;
let errorMessage;
while (line < stack.length && stack[line].indexOf("ReferenceError") !== 0) {
line++;
}
@ -455,11 +454,13 @@ module.exports = function(RED) {
errorMessage += " (line "+lineno+", col "+cha+")";
}
}
if (errorMessage) {
err.message = errorMessage
}
}
if (!errorMessage) {
errorMessage = err.toString();
}
done(errorMessage);
// Pass the whole error object so any additional properties
// (such as cause) are preserved
done(err);
}
else if (typeof err === "string") {
done(err);

View File

@ -678,6 +678,9 @@ class Flow {
if (logMessage.hasOwnProperty('stack')) {
errorMessage.error.stack = logMessage.stack;
}
if (logMessage.hasOwnProperty('cause')) {
errorMessage.error.cause = logMessage.cause;
}
targetCatchNode.receive(errorMessage);
handled = true;
});