Add error handling to AsyncWriter.Flush