Improve the error handling for getting the ancestry