Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec.Run does not return exec.ErrNotFound error #18

Open
borismattijssen opened this issue Feb 27, 2017 · 5 comments
Open

exec.Run does not return exec.ErrNotFound error #18

borismattijssen opened this issue Feb 27, 2017 · 5 comments

Comments

@borismattijssen
Copy link

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()) {.

@mitchellh
Copy link
Owner

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

@ryanwalls
Copy link

@mitchellh Any update on this?

ethanmick added a commit to virtyx-technologies/go-homedir that referenced this issue Jan 24, 2018
As explained here: mitchellh#18

The exec.ErrNotFound error is returned, but this error is wrapped by
exec.Error() so the returned error will never be exec.ErrNotFound.
@tmm1
Copy link

tmm1 commented Oct 2, 2019

Another alternative is:

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

@justinfx
Copy link

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.

@FrankReh
Copy link

FrankReh commented Dec 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants