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

cli: sequence cli.Ui operations #6865

Merged
merged 1 commit into from
Dec 16, 2019
Merged

cli: sequence cli.Ui operations #6865

merged 1 commit into from
Dec 16, 2019

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Dec 16, 2019

Fixes a bug where if a command flag parsing errors, the resulting error
and help usage messages get interleaved in unexpected and non-user
friendly way.

The reason is that we have flag parsing library effectively writes to
ui.Error in a goroutine. This is problematic: first, we lose the sequencing between help
usage and error message; second, cli.Ui methods are not concurrent safe.

Here, we introduce a custom error writer that buffers result and calls
ui.Error() in the write method and in the same goroutine.

For context, we need to wrap ui.Error because it's line-oriented, while
flags library expects a io.Writer which is bytes oriented.

Fixes #6857

Fixes a bug where if a command flag parsing errors, the resulting error
and help usage messages get interleaved in unexpected and non-user
friendly way.

The reason is that we have flag parsing library effectively writes to
ui.Error in a goroutine.  This is problematic: first, we lose the sequencing between help
usage and error message; second, cli.Ui methods are not concurrent safe.

Here, we introduce a custom error writer that buffers result and calls
ui.Error() in the write method and in the same goroutine.

For context, we need to wrap ui.Error because it's line-oriented, while
flags library expects a io.Writer which is bytes oriented.
@notnoop notnoop requested a review from tgross December 16, 2019 15:46
@notnoop notnoop added this to the 0.10.3 milestone Dec 16, 2019
@notnoop notnoop added this to Triaged in Nomad - Community Issues Triage via automation Dec 16, 2019
@notnoop notnoop moved this from Triaged to In Review in Nomad - Community Issues Triage Dec 16, 2019
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@notnoop notnoop merged commit 8abb4e6 into master Dec 16, 2019
Nomad - Community Issues Triage automation moved this from In Review to Done Dec 16, 2019
@notnoop notnoop deleted the b-cli-error-formatting branch December 16, 2019 21:06
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: inconsistent and incorrect error placement on flag not defined
2 participants