mitchellh/go-homedir

exec.Run does not return exec.ErrNotFound error

borismattijssen opened this issue · 5 comments

I don't have getent on my system, so the dirUnix function failed to execute it. It checks (https://github.com/mitchellh/go-homedir/blob/master/homedir.go#L87) if the exec.ErrNotFound error is returned, but this error is wrapped by exec.Error() so the returned error will never be exec.ErrNotFound.

The actual returned error message is: exec: "getent": executable file not found in $PATH, whereas it expected the following: executable file not found in $PATH.

A fix would be if strings.HasSufix(err.Error(), err.ErrNotFound.Error()) {.

Ah darn. Yes, we should just do a string check for this unfortunately. :(

@mitchellh Any update on this?

tmm1 commented

Another alternative is:

    if err, ok := err.(*exec.Error); ok && err.Err == exec.ErrNotFound {

I just hit this problem and had to track it down to a bit to find it coming from this library while I run my binary in a completely empty env. Is there no movement on this bug? Seems like a library that is trying to abstract finding the user homedir should probably be able to work around this case as well.

Another alternative is to ignore any kind of error so the final attempt to use the shell to cd and pwd can play out. This would mirror the darwin case where only a chain of successful steps leads to an early return. Just posting this for folks who are considering cloning the repo themselves.