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

fix: exit early on run --version #3067

Merged
merged 2 commits into from Aug 5, 2022
Merged

Conversation

ldez
Copy link
Member

@ldez ldez commented Aug 5, 2022

Fixes #3066

@ldez ldez added bug Something isn't working area: CLI Related to CLI labels Aug 5, 2022
Copy link
Member

@bombsimon bombsimon left a comment

Choose a reason for hiding this comment

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

LGTM!

Do you know what change made the command not exit successfully after returning nil? Just pondering if it's worth adding some details to why we have to do this

@ldez
Copy link
Member Author

ldez commented Aug 5, 2022

Do you know what change made the command not exit successfully after returning nil?

It's because the version is displayed inside the preRun so a return nil will not stop the run.

"github.com/golangci/golangci-lint/pkg/logutils"
)

func (e *Executor) persistentPreRun(_ *cobra.Command, _ []string) error {
if e.cfg.Run.PrintVersion {
_, _ = fmt.Fprintf(logutils.StdOut, "golangci-lint has version %s built from %s on %s\n", e.version, e.commit, e.date)
return nil
os.Exit(exitcodes.Success) // a return nil is not enough to stop the process because we are inside the `preRun`.
Copy link
Contributor

Choose a reason for hiding this comment

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

heh, I wondered why we did a return instead of just an exit here :)

@ldez ldez merged commit da3b149 into golangci:master Aug 5, 2022
16 checks passed
@ldez ldez deleted the fix/version-hang branch August 5, 2022 13:49
SeigeC pushed a commit to SeigeC/golangci-lint that referenced this pull request Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CLI Related to CLI bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

golangci-lint run --version hangs instead of exiting
3 participants