close open file on error