mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
improve "Unexpected Node Error" logging
- fixes #3389 - adds additional info to aid sourcing the issue - removes lots of undefined info when node type is incorrect - stores and reports original stack before internal try/catch exception - ensure this._flow is something before attempting to call `handleError`
This commit is contained in:
parent
bffb91f196
commit
efd8c1229d
@ -503,10 +503,25 @@ function log_helper(self, level, msg) {
|
||||
o.name = self.name;
|
||||
}
|
||||
// See https://github.com/node-red/node-red/issues/3327
|
||||
// See https://github.com/node-red/node-red/issues/3389
|
||||
|
||||
let srcError;
|
||||
if (msg instanceof Error) {
|
||||
srcError = msg;//use existing err object for actual stack
|
||||
} else {
|
||||
srcError = new Error(msg);//generate a new error for generate a stack
|
||||
}
|
||||
try {
|
||||
if(self instanceof Node && self._flow) {
|
||||
self._flow.log(o);
|
||||
} else {
|
||||
//if self._flow is not present, this is not a node-red Node
|
||||
//Set info to "Node object is not a node-red Node" to point out the `Node type` problem in log
|
||||
logUnexpectedError(self, srcError, "Node object is not a node-red Node")
|
||||
}
|
||||
} catch(err) {
|
||||
logUnexpectedError(self, err)
|
||||
//build an unexpected error report indicating using the original error (for better stack trace)
|
||||
logUnexpectedError(self, srcError, `An error occured attempting to make a log entry: ${err}`)
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -531,7 +546,7 @@ Node.prototype.error = function(logMessage,msg) {
|
||||
logMessage = logMessage || "";
|
||||
}
|
||||
var handled = false;
|
||||
if (msg && typeof msg === 'object') {
|
||||
if (this._flow && msg && typeof msg === 'object') {
|
||||
handled = this._flow.handleError(this,logMessage,msg);
|
||||
}
|
||||
if (!handled) {
|
||||
@ -619,27 +634,34 @@ function inspectObject(flow) {
|
||||
}
|
||||
}
|
||||
|
||||
function logUnexpectedError(node, error) {
|
||||
let moduleInfo = node._module?`${node._module.module}@${node._module.version}`:"undefined"
|
||||
Log.error(`
|
||||
function logUnexpectedError(node, error, info) {
|
||||
const header = `
|
||||
********************************************************************
|
||||
Unexpected Node Error
|
||||
${error.stack}
|
||||
Node:
|
||||
Type: ${node.type}
|
||||
Module: ${moduleInfo}
|
||||
ID: ${node._alias||node.id}
|
||||
Properties:
|
||||
${inspectObject(node)}
|
||||
Flow: ${node._flow?node._flow.path:'undefined'}
|
||||
Type: ${node._flow?node._flow.TYPE:'undefined'}
|
||||
Properties:
|
||||
${node._flow?inspectObject(node._flow):'undefined'}
|
||||
********************************************************************`;
|
||||
|
||||
const footer = `
|
||||
Please report this issue, including the information logged above:
|
||||
https://github.com/node-red/node-red/issues/
|
||||
********************************************************************
|
||||
`)
|
||||
********************************************************************`;
|
||||
|
||||
let detail = [`Info:\n ${info || 'No additional info'}`];
|
||||
|
||||
//Include Error info?
|
||||
if(error && error.stack){
|
||||
detail.push(`Stack:\n ${error.stack}`)
|
||||
}
|
||||
//Include Node info?
|
||||
if(node && (node._module || node.type)){
|
||||
const moduleInfo = node._module?`${node._module.module}@${node._module.version}`:"undefined";
|
||||
const id = node._alias||node.id||"undefined";
|
||||
detail.push(`Node:\n Type: ${node.type}\n Module: ${moduleInfo}\n ID: ${id}\n Properties:\n ${inspectObject(node)}`)
|
||||
}
|
||||
//Include Flow info?
|
||||
if(node && node._flow){
|
||||
detail.push(`Flow: ${node._flow.path}\n Type: ${node._flow.TYPE}\n Properties:\n ${inspectObject(node._flow)}`)
|
||||
}
|
||||
Log.error(`${header}\n${detail.join("\n")}\n${footer}`);
|
||||
}
|
||||
|
||||
module.exports = Node;
|
||||
|
Loading…
Reference in New Issue
Block a user