I mean if `$dir` is not a directory, we should throw exception (the check can be done earlier).
This is just for safety purpose to avoid big trouble.