Handle file eof and error cases