first write the error second update the status