Handle file error properly