Avoid an NPE if readdir() attempts to read a non-existant directory
and ends up with an error instead of an array of directory entries.
Ensure that readdirSync() throws if an error occurs.