Add write error checks