close file when error