Handle `is a directory` error

Closes #4616