Add line numbers to errors

This commit is contained in:
Jan Oberhauser 2021-12-23 15:16:42 +01:00
parent fa760ee26b
commit 0f1b8779e4
2 changed files with 27 additions and 0 deletions

View file

@ -127,6 +127,18 @@ return items;`,
if (this.continueOnFail()) {
items=[{json:{ error: error.message }}];
} else {
// Try to find the lien number which contains the error and attach to error message
const stackLines = error.stack.split('\n');
if (stackLines.length > 0) {
const lineParts = stackLines[1].split(':');
if (lineParts.length > 2) {
const lineNumber = lineParts.splice(-2, 1);
if (!isNaN(lineNumber)) {
error.message = `${error.message} [Line ${lineNumber}]`;
}
}
}
return Promise.reject(error);
}
}

View file

@ -120,6 +120,21 @@ return item;`,
returnData.push({json:{ error: error.message }});
continue;
} else {
// Try to find the lien number which contains the error and attach to error message
const stackLines = error.stack.split('\n');
if (stackLines.length > 0) {
const lineParts = stackLines[1].split(':');
if (lineParts.length > 2) {
const lineNumber = lineParts.splice(-2, 1);
if (!isNaN(lineNumber)) {
error.message = `${error.message} [Line ${lineNumber} | Item Index: ${itemIndex}]`;
return Promise.reject(error);
}
}
}
error.message = `${error.message} [Item Index: ${itemIndex}]`;
return Promise.reject(error);
}
}