go-homedir icon indicating copy to clipboard operation
go-homedir copied to clipboard

exec.Run does not return exec.ErrNotFound error

Open borismattijssen opened this issue 7 years ago • 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()) {.

borismattijssen avatar Feb 27 '17 10:02 borismattijssen

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

mitchellh avatar Feb 27 '17 16:02 mitchellh

@mitchellh Any update on this?

ryanwalls avatar Nov 07 '17 16:11 ryanwalls

Another alternative is:

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

tmm1 avatar Oct 02 '19 22:10 tmm1

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.

justinfx avatar Oct 14 '20 03:10 justinfx

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.

FrankReh avatar Dec 02 '20 16:12 FrankReh