close file on error