Fix file error handling