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

Make it return something in Docker #21

Closed
raido opened this issue Jan 25, 2019 · 9 comments · Fixed by #22
Closed

Make it return something in Docker #21

raido opened this issue Jan 25, 2019 · 9 comments · Fixed by #22

Comments

@raido
Copy link
Contributor

raido commented Jan 25, 2019

https://github.com/sindresorhus/username/blob/master/index.js#L29

Above userInfo() call should be wrapped in try catch block.

This causes crash when running for example in docker container like:

docker run --user $(id -u): $(id -g) ...

Because user in docker then will be without $HOME and username both.

@raido
Copy link
Contributor Author

raido commented Jan 25, 2019

@sindresorhus
Copy link
Owner

The os.userInfo() method is not documented to throw. You should open an issue on Node.js about this instead. This looks like a Node.js bug.

@raido
Copy link
Contributor Author

raido commented Jan 26, 2019

It seems it is expected behaviour from Node and just not documented.

I am not sure now should we catch and return empty object or return rejected promise and let consumers of this package deal with the problem.

@sindresorhus
Copy link
Owner

Thanks for opening the issue on Node.js. I have worked around the issue on my end now.

@raido
Copy link
Contributor Author

raido commented Jan 26, 2019

This will not work in docker context we have here. Yes, it will not hard crash but it will not return single line result either.

Now when os.userInfo throws, we end up calling id -un which now returns following as stdout:

id: cannot find name for user ID <userId>
<userId>

The -n argument has no username to return.

@sindresorhus
Copy link
Owner

Then I don't really know a way to get the username in Docker. I don't use Docker, but PR welcome if you can think of a way.

@sindresorhus
Copy link
Owner

Maybe something like this: https://stackoverflow.com/a/38927208/64949

@sindresorhus sindresorhus changed the title A system error occurred: uv_os_get_passwd returned ENOENT (no such file or directory) Make it return something in Docker Jan 26, 2019
@sindresorhus sindresorhus reopened this Jan 26, 2019
@raido
Copy link
Contributor Author

raido commented Jan 26, 2019

I am not sure there is a way. There is no actual user in the container when —user flag is present.

I guess if we could detect the situation some how and just return user-<id> as resulting string, it would be close enough.

I have some ideas, I’ll try them out.

@raido
Copy link
Contributor Author

raido commented Jan 26, 2019

I opened a PR as possible solution.

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

Successfully merging a pull request may close this issue.

2 participants