mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Make send-error behaviour optional in file node
Existing nodes will have sendError enabled. New instances will default to it being disabled.
This commit is contained in:
parent
47e2707fd3
commit
0fd8d0e2bf
@ -762,6 +762,7 @@
|
||||
"breakchunks": "Break into chunks",
|
||||
"breaklines": "Break into lines",
|
||||
"filelabel": "file",
|
||||
"sendError": "Send message on error (legacy mode)",
|
||||
"deletelabel": "delete __file__"
|
||||
},
|
||||
"action": {
|
||||
|
@ -62,6 +62,11 @@
|
||||
<option value="stream" data-i18n="file.output.stream"></option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label></label>
|
||||
<input type="checkbox" id="node-input-sendError" style="width:auto">
|
||||
<label style="width:auto; margin-bottom:0; vertical-align: middle;" for="node-input-sendError" data-i18n="file.label.sendError"></label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
||||
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
||||
@ -82,6 +87,12 @@
|
||||
<dd>The contents of the file as either a string or binary buffer.</dd>
|
||||
<dt class="optional">filename <span class="property-type">string</span></dt>
|
||||
<dd>If not configured in the node, this optional property sets the name of the file to be read.</dd>
|
||||
<dt class="optional">error <span class="property-type">object</span></dt>
|
||||
<dd><i>deprecated</i>: If enabled in the node, when the node hits an error
|
||||
reading the file, it will send a message with no <code>payload</code>
|
||||
and this <code>error</code> property set to the error details. This
|
||||
mode of behaviour is deprecated and not enabled by default for new
|
||||
instances of the node. See below for more information.</dd>
|
||||
</dl>
|
||||
<h3>Details</h3>
|
||||
<p>The filename should be an absolute path, otherwise it will be relative to
|
||||
@ -89,6 +100,13 @@
|
||||
<p>On Windows, path separators may need to be escaped, for example: <code>\\Users\\myUser</code>.</p>
|
||||
<p>Optionally, a text file can be split into lines, outputting one message per line, or a binary file
|
||||
file into smaller buffer chunks, the chunk size is operating system dependant, but typically 64k (linux/mac) or 41k (Windows).</p>
|
||||
<h4>Legacy error handling</h4>
|
||||
<p>Before Node-RED 0.17, if this node hit an error whilst reading the file, it would
|
||||
send a message with no <code>msg.payload</code> and <code>msg.error</code> set to the
|
||||
details of the error. This is a deprecated mode of behaviour for the node that new
|
||||
instances will not do. If required, this mode can be re-enabled within the node
|
||||
configuration.</p>
|
||||
<p>Errors should be caught and handled using a Catch node.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -130,7 +148,8 @@
|
||||
name: {value:""},
|
||||
filename: {value:""},
|
||||
format: {value:"utf8"},
|
||||
chunk: {value:false}
|
||||
chunk: {value:false},
|
||||
sendError: {value: false}
|
||||
},
|
||||
color:"BurlyWood",
|
||||
inputs:1,
|
||||
@ -146,6 +165,9 @@
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.sendError === undefined) {
|
||||
$("#node-input-sendError").prop("checked",true);
|
||||
}
|
||||
$("#node-input-format").on("change",function() {
|
||||
if ($("#node-input-format").val() === "utf8") {
|
||||
$("#buffer-input-type").hide();
|
||||
|
@ -98,6 +98,11 @@ module.exports = function(RED) {
|
||||
this.filename = n.filename;
|
||||
this.format = n.format;
|
||||
this.chunk = false;
|
||||
if (n.sendError === undefined) {
|
||||
this.sendError = true;
|
||||
} else {
|
||||
this.sendError = n.sendError;
|
||||
}
|
||||
if (this.format === "lines") { this.chunk = true; }
|
||||
if (this.format === "stream") { this.chunk = true; }
|
||||
var node = this;
|
||||
@ -173,10 +178,12 @@ module.exports = function(RED) {
|
||||
})
|
||||
.on('error', function(err) {
|
||||
node.error(err, msg);
|
||||
if (node.sendError) {
|
||||
var sendMessage = RED.util.cloneMessage(msg);
|
||||
delete sendMessage.payload;
|
||||
sendMessage.error = err;
|
||||
node.send(sendMessage);
|
||||
}
|
||||
})
|
||||
.on('end', function() {
|
||||
if (node.chunk === false) {
|
||||
|
Loading…
Reference in New Issue
Block a user