fix error message when invalid directory

Fixes #1253