Fix error handling of read_directory

Signed-off-by: Sebastian Ramacher <sebastian@ramacher.at>