Add error message when write fails