getting those errors again, but it still worked for some reason

I think the problem was that writer.write and writer.truncate
both call the writeend event, so the error is on the truncate
rather than the write, but it still doesn't make sense.
I moved the truncate to the write callback, maybe that will help.