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

No easy way to detect formatting problems #41

Closed
kirasglimmer opened this issue Mar 10, 2020 · 3 comments
Closed

No easy way to detect formatting problems #41

kirasglimmer opened this issue Mar 10, 2020 · 3 comments
Labels

Comments

@kirasglimmer
Copy link

kirasglimmer commented Mar 10, 2020

hostess -n fmt does not affect exit codes if there is a formatting problem. For example, my hosts file has 2 contrived duplicates:

duplicate hostname entry for test -> 127.0.0.1
duplicate hostname entry for kubernetes.docker.internal -> 127.0.0.1

When I run sudo hostess -n fmt, it reports:

~: hostess -n fmt
duplicate hostname entry for test -> 127.0.0.1
duplicate hostname entry for kubernetes.docker.internal -> 127.0.0.1
... remainder redacted for security ...

Then, echo $? reports 0:

~: echo $?
0

I would expect the exit code to be non-zero when there are duplicates to make automation with hostess easier. Non-zero exit codes were working in earlier versions (pre 0.4.0), and as such, our automation scripts have broken.

@cbednarski cbednarski added the bug label Mar 10, 2020
@cbednarski
Copy link
Owner

Thanks for the report! Apologies for the change in behavior here. I did not have test coverage for exit codes so I did not catch this change, but I have started adding test coverage to the frontend so I should be able to specify this behavior and make sure it sticks going forward.

I'd like to get your feedback on expectations here. My expectation is in the case of a dupe (not a collision) and -n is not passed, we can fix the dupe and move on (soft error / warning), as in #39. I think this is reasonable since in the case of a duplicate the fix is deterministic.

To satisfy your case, I can further specify that in the case of a dupe and -n is specified this becomes a hard error.

A collision (same hostname pointing to two different IPs) will always be a hard error because I can't choose the correct IP for you.

@kirasglimmer
Copy link
Author

Thanks.

It seems reasonable that if -n is not passed, then a 0 exit code is acceptable since hostess will be fixing the file. So, as long as hostess is able to successfully do that (i.e., it was run with sudo hostess fmt), then a 0 seems correct.

If -n is passed, then any type of duplicate should result in an exit code. If you want to vary the exit code (say a -1 for duplicate name, same IP, and a -2 for same hostname, different IPs), that also makse sense. Our base requirement is just a non-zero exit code for any type of duplicate.

@cbednarski
Copy link
Owner

@DacheW This should now be fixed in version 0.5.2. Thanks again for the report!

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

No branches or pull requests

2 participants