1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

add error objects to all node.errors so they can be caught.

to close #767
This commit is contained in:
Dave Conway-Jones 2021-03-11 19:36:37 +00:00
parent c66daa6220
commit ae95fecc8f
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 9 additions and 9 deletions

View File

@ -72,7 +72,7 @@ module.exports = function(RED) {
}); });
} }
else { else {
this.error(RED._("serial.errors.missing-conf")); this.error(RED._("serial.errors.missing-conf"), {error:"serial.errors.missing-conf"});
} }
this.on("close", function(done) { this.on("close", function(done) {
@ -109,7 +109,7 @@ module.exports = function(RED) {
}); });
} }
else { else {
this.error(RED._("serial.errors.missing-conf")); this.error(RED._("serial.errors.missing-conf"), {error:"serial.errors.missing-conf"});
} }
this.on("close", function(done) { this.on("close", function(done) {
@ -186,7 +186,7 @@ module.exports = function(RED) {
}); });
} }
else { else {
this.error(RED._("serial.errors.missing-conf")); this.error(RED._("serial.errors.missing-conf"), {error:"serial.errors.missing-conf"});
} }
this.on("close", function(done) { this.on("close", function(done) {
@ -347,7 +347,7 @@ module.exports = function(RED) {
if (err) { if (err) {
if (err.toString() !== olderr) { if (err.toString() !== olderr) {
olderr = err.toString(); olderr = err.toString();
RED.log.error(RED._("serial.errors.error",{port:port,error:olderr})); RED.log.error(RED._("serial.errors.error",{port:port,error:olderr}), {error:"serial.errors.error"});
} }
obj.tout = setTimeout(function() { obj.tout = setTimeout(function() {
setupSerial(); setupSerial();
@ -355,7 +355,7 @@ module.exports = function(RED) {
} }
}); });
obj.serial.on('error', function(err) { obj.serial.on('error', function(err) {
RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()})); RED.log.error(RED._("serial.errors.error",{port:port,error:err.toString()}), {error:"serial.errors.error"});
obj._emitter.emit('closed'); obj._emitter.emit('closed');
if (obj.tout) { clearTimeout(obj.tout); } if (obj.tout) { clearTimeout(obj.tout); }
obj.tout = setTimeout(function() { obj.tout = setTimeout(function() {
@ -366,7 +366,7 @@ module.exports = function(RED) {
if (!obj._closing) { if (!obj._closing) {
if (olderr !== "unexpected") { if (olderr !== "unexpected") {
olderr = "unexpected"; olderr = "unexpected";
RED.log.error(RED._("serial.errors.unexpected-close",{port:port})); RED.log.error(RED._("serial.errors.unexpected-close",{port:port}), {error:"serial.errors.unexpected-close"});
} }
obj._emitter.emit('closed'); obj._emitter.emit('closed');
if (obj.tout) { clearTimeout(obj.tout); } if (obj.tout) { clearTimeout(obj.tout); }
@ -472,7 +472,7 @@ module.exports = function(RED) {
connections[port]._closing = true; connections[port]._closing = true;
try { try {
connections[port].close(function() { connections[port].close(function() {
RED.log.info(RED._("serial.errors.closed",{port:port})); RED.log.info(RED._("serial.errors.closed",{port:port}), {error:"serial.errors.closed"});
done(); done();
}); });
} }

View File

@ -1,9 +1,9 @@
{ {
"name" : "node-red-node-serialport", "name" : "node-red-node-serialport",
"version" : "0.11.1", "version" : "0.12.0",
"description" : "Node-RED nodes to talk to serial ports", "description" : "Node-RED nodes to talk to serial ports",
"dependencies" : { "dependencies" : {
"serialport" : "^9.0.2" "serialport" : "^9.0.7"
}, },
"repository" : { "repository" : {
"type":"git", "type":"git",