mirror of https://github.com/node-red/node-red.git
fix: prevent stale error handler references in file node append mode
Use write callback's error argument instead of adding/removing error handlers. This ensures the correct msg/done scope is used for each write operation. The stream-level error handler now only handles errors for dynamic filenames, while static filename writes handle errors via the write callback. Addresses review feedback from @knolleary. Fixes #5453pull/5460/head
parent
1019d52f78
commit
4822636fd3
|
|
@ -183,15 +183,25 @@ module.exports = function(RED) {
|
|||
} catch(err) {
|
||||
}
|
||||
});
|
||||
// Note: For static filenames, write errors are handled in the write callback.
|
||||
// This handler catches stream-level errors for dynamic filenames.
|
||||
node.wstream.on("error", function(err) {
|
||||
node.error(RED._("file.errors.appendfail",{error:err.toString()}),msg);
|
||||
done();
|
||||
// Only handle if not a static filename (those use write callback)
|
||||
if (node.filenameType !== "str" && node.filenameType !== "env") {
|
||||
node.error(RED._("file.errors.appendfail",{error:err.toString()}),msg);
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (node.filenameType === "str" || node.filenameType === "env") {
|
||||
// Static filename - write and reuse the stream next time
|
||||
node.wstream.write(buf, function() {
|
||||
nodeSend(msg);
|
||||
// Use write callback's error argument for proper scoping of msg/done
|
||||
node.wstream.write(buf, function(err) {
|
||||
if (err) {
|
||||
node.error(RED._("file.errors.appendfail",{error:err.toString()}),msg);
|
||||
} else {
|
||||
nodeSend(msg);
|
||||
}
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue