Bail on chdir failure

Fixes #303