check for errors when flushing the stream