Handle errors from `os.scandir()` and `ScandirIterator` similarly, which lets us loop over directory entries with `for`.