Node-red-node-email fails with attachments 0.1% of the time

I'm using node-red-node-email to send a daily report with graphs and such. Because outlook is... well... challenged, I have to attach images of graphs instead of linking to them. I would like to learn how to achieve this at a later time but for now attachments work fine 99.9% of the time. When they don't I get this message:

TypeError: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of Object

The only way I have been able to resolve this is by uninstalling and reinstalling the node. I cannot follow the code well enough to determine where this failure happens, but this seems to be something internal to the node and I'm not able to manipulate the "chunk" argument directly through node configuration or message properties.

Anyone have any experience with this issue?

Are there more error lines around that in the log ?

Sorry, none at all.

Okay after much trial and error, I have finally discovered the issue. I was storing image buffers in the flow context and recalling them in another function to be organized into a node mailer attachment. Most of the time this works, but other times I think flow.get() was returning an array rather than an image buffer. I fixed this passing the recalled image buffer through new Buffer(flow.get(yada yada)) to make sure it was a proper image buffer and not an array.

You can confirm that by checking the type of the object. It sounds unlikely to me that the the type would vary. I suspect something more subtle is going on. Possibly a timing issue.

If you're thinking race condition, the first event that generates the buffers happens about 8 hours before the second even that pushes them into email attachments.

At any rate, I will try to rewrite this flow to eliminate the flow context completely and just pass all my buffers into a join node to collect all the parts and do it all up that way.

Are you using persistent context? Is it possible that node red restarted in that 8 hours?

Yes, I'm using persistent context storage for these. Update though:

After looking at it more, I'm realizing that there's actually an error in the data being fed to the chart image generator node that should be generating the buffer. In this case, the node is not getting good data and is returning an actual object. So, it looks like this is simply in my flow, not in node-red-node-email.

Holy moly this all stemmed from a DB with a bad default expression in a table. :joy:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.