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",
|
"breakchunks": "Break into chunks",
|
||||||
"breaklines": "Break into lines",
|
"breaklines": "Break into lines",
|
||||||
"filelabel": "file",
|
"filelabel": "file",
|
||||||
|
"sendError": "Send message on error (legacy mode)",
|
||||||
"deletelabel": "delete __file__"
|
"deletelabel": "delete __file__"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<h3>Details</h3>
|
<h3>Details</h3>
|
||||||
<p>Each message payload will be added to the end of the file, optionally appending
|
<p>Each message payload will be added to the end of the file, optionally appending
|
||||||
a newline (\n) character between each one.</p>
|
a newline (\n) character between each one.</p>
|
||||||
<p>If <code>msg.filename</code> is used the file will be closed after every write.
|
<p>If <code>msg.filename</code> is used the file will be closed after every write.
|
||||||
For best performance use a fixed filename.</p>
|
For best performance use a fixed filename.</p>
|
||||||
<p>It can be configured to overwrite the entire file rather than append. For example,
|
<p>It can be configured to overwrite the entire file rather than append. For example,
|
||||||
when writing binary data to a file, such as an image, this option should be used
|
when writing binary data to a file, such as an image, this option should be used
|
||||||
@ -62,6 +62,11 @@
|
|||||||
<option value="stream" data-i18n="file.output.stream"></option>
|
<option value="stream" data-i18n="file.output.stream"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
<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">
|
<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>
|
<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>
|
<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>
|
<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>
|
</dl>
|
||||||
<h3>Details</h3>
|
<h3>Details</h3>
|
||||||
<p>The filename should be an absolute path, otherwise it will be relative to
|
<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>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
|
<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>
|
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>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -130,7 +148,8 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
filename: {value:""},
|
filename: {value:""},
|
||||||
format: {value:"utf8"},
|
format: {value:"utf8"},
|
||||||
chunk: {value:false}
|
chunk: {value:false},
|
||||||
|
sendError: {value: false}
|
||||||
},
|
},
|
||||||
color:"BurlyWood",
|
color:"BurlyWood",
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -146,6 +165,9 @@
|
|||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
|
if (this.sendError === undefined) {
|
||||||
|
$("#node-input-sendError").prop("checked",true);
|
||||||
|
}
|
||||||
$("#node-input-format").on("change",function() {
|
$("#node-input-format").on("change",function() {
|
||||||
if ($("#node-input-format").val() === "utf8") {
|
if ($("#node-input-format").val() === "utf8") {
|
||||||
$("#buffer-input-type").hide();
|
$("#buffer-input-type").hide();
|
||||||
|
@ -98,6 +98,11 @@ module.exports = function(RED) {
|
|||||||
this.filename = n.filename;
|
this.filename = n.filename;
|
||||||
this.format = n.format;
|
this.format = n.format;
|
||||||
this.chunk = false;
|
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 === "lines") { this.chunk = true; }
|
||||||
if (this.format === "stream") { this.chunk = true; }
|
if (this.format === "stream") { this.chunk = true; }
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -173,10 +178,12 @@ module.exports = function(RED) {
|
|||||||
})
|
})
|
||||||
.on('error', function(err) {
|
.on('error', function(err) {
|
||||||
node.error(err, msg);
|
node.error(err, msg);
|
||||||
var sendMessage = RED.util.cloneMessage(msg);
|
if (node.sendError) {
|
||||||
delete sendMessage.payload;
|
var sendMessage = RED.util.cloneMessage(msg);
|
||||||
sendMessage.error = err;
|
delete sendMessage.payload;
|
||||||
node.send(sendMessage);
|
sendMessage.error = err;
|
||||||
|
node.send(sendMessage);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.on('end', function() {
|
.on('end', function() {
|
||||||
if (node.chunk === false) {
|
if (node.chunk === false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user