Direnv: In non-existent directory, reloading shell prompt -> error LoadConfig() Getwd failed: "getwd: no such file or directory"

Created on 3 Feb 2019  路  5Comments  路  Source: direnv/direnv

Issue description

When the current working directory does not exist, loading the shell prompt (_e.g.,_ by hitting <Enter>) causes the following error to appear:

direnv: error LoadConfig() Getwd failed: "getwd: no such file or directory"

Steps to reproduce

$ mkdir foo
$ cd foo
$ rmdir $(pwd)
direnv: error LoadConfig() Getwd failed: "getwd: no such file or directory"
Usability

Most helpful comment

Whoops, good point.

As a general principle, I would expect to see an error message only when a program has failed to perform one of its expected functions. Since I don't expect direnv to do anything in a non-existent directory, I would expect to see no error message at all.

All 5 comments

what is the behaviour that you would expect?

Whoops, good point.

As a general principle, I would expect to see an error message only when a program has failed to perform one of its expected functions. Since I don't expect direnv to do anything in a non-existent directory, I would expect to see no error message at all.

I agree, direnv shouldn't be doing anything (from a user's point of view) in a directory that doesn't exist.

I'd suggest:

  1. Store the CWD when running the hook (initialize to /?)
  2. If the stored CWD directory doesn't exist next time, exit early

I'd suggest:

1. Store the CWD when running the hook (initialize to /?)

2. If the stored CWD directory doesn't exist next time, exit early

No need to store anything. Simply catch this error or check for existence beforehand.

Was this page helpful?
0 / 5 - 0 ratings