mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
commit
25dba1a6d5
@ -83,6 +83,7 @@ function createNode(flow,config) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Object.defineProperty(conf,'_module', {value: typeRegistry.getNodeInfo(type), enumerable: false, writable: true })
|
||||
Object.defineProperty(conf,'_flow', {value: flow, enumerable: false, writable: true })
|
||||
newNode = new nodeTypeConstructor(conf);
|
||||
} catch (err) {
|
||||
|
@ -59,6 +59,9 @@ function Node(n) {
|
||||
// which we can tolerate as they are the same object.
|
||||
Object.defineProperty(this,'_flow', {value: n._flow, enumerable: false, writable: true })
|
||||
}
|
||||
if (n._module) {
|
||||
Object.defineProperty(this,'_module', {value: n._module, enumerable: false, writable: true })
|
||||
}
|
||||
this.updateWires(n.wires);
|
||||
}
|
||||
|
||||
@ -496,7 +499,12 @@ function log_helper(self, level, msg) {
|
||||
if (self.name) {
|
||||
o.name = self.name;
|
||||
}
|
||||
self._flow.log(o);
|
||||
// See https://github.com/node-red/node-red/issues/3327
|
||||
try {
|
||||
self._flow.log(o);
|
||||
} catch(err) {
|
||||
logUnexpectedError(self, err)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Log an INFO level message
|
||||
@ -576,4 +584,59 @@ Node.prototype.status = function(status) {
|
||||
this._flow.handleStatus(this,status);
|
||||
};
|
||||
|
||||
|
||||
function inspectObject(flow) {
|
||||
try {
|
||||
let properties = new Set()
|
||||
let currentObj = flow
|
||||
do {
|
||||
if (!Object.getPrototypeOf(currentObj)) { break }
|
||||
Object.getOwnPropertyNames(currentObj).map(item => properties.add(item))
|
||||
} while ((currentObj = Object.getPrototypeOf(currentObj)))
|
||||
let propList = [...properties.keys()].map(item => `${item}[${(typeof flow[item])[0]}]`)
|
||||
propList.sort();
|
||||
let result = [];
|
||||
let line = "";
|
||||
while (propList.length > 0) {
|
||||
let prop = propList.shift()
|
||||
if (line.length+prop.length > 80) {
|
||||
result.push(line)
|
||||
line = "";
|
||||
} else {
|
||||
line += " "+prop
|
||||
}
|
||||
}
|
||||
if (line.length > 0) {
|
||||
result.push(line);
|
||||
}
|
||||
return result.join("\n ")
|
||||
|
||||
} catch(err) {
|
||||
return "Failed to capture object properties: "+err.toString()
|
||||
}
|
||||
}
|
||||
|
||||
function logUnexpectedError(node, error) {
|
||||
let moduleInfo = node._module?`${node._module.module}@${node._module.version}`:"undefined"
|
||||
Log.error(`
|
||||
********************************************************************
|
||||
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'}
|
||||
|
||||
Please report this issue, including the information logged above:
|
||||
https://github.com/node-red/node-red/issues/
|
||||
********************************************************************
|
||||
`)
|
||||
}
|
||||
|
||||
module.exports = Node;
|
||||
|
Loading…
Reference in New Issue
Block a user