improve error handling for readFile