-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Persistent post run exits early when run is successful in Magefile targets #4137
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello, golangci-lint is not designed to be used as a library and we discourage that. I understand your problem but you are using golangci-lint in a way that we highly discourage. My first thought is to not accept changes that encourage the use of golangci-lint as a library. |
Regardless of use case I would argue that having multiple exit points for application is bad practice and makes the control flow harder to follow. |
This is a purely theoretical point of view, and I can agree with that, but a rule should be evaluated inside a context, not as a dogma. We need to control the exit code and cobra doesn't provide a way to control it. I can use this argument in an opposite way: currently, we control all (except some edge cases) exit codes in one place. |
Sure, I was just merely suggesting that this might still be worth looking into regardless the circumtances where user encountered this issue. |
My message was oriented as an answer to the user but I evaluated the whole context. I didn't close the issue, to get more feedback, because it was possible I missed something. |
Well, I'm glad to help :D |
Welcome
Description of the problem
We are running golangci-lint using a Golang make/rake -like tool Mage.
There, we have defined a mage target that runs linting as well as other tasks one-by-one in serial order. We encountered that
golangci-lint
exits too early and the rest of the tasks following that were not executed.Further examples are provided in the repo URL in the reproductible code section, but in short, when defining mage targets such as:
running
mage checkall
skips the latter.Now, when running golangci-lint with debugger it seems, that:
os.exit
was run inpkg/commands/root.go:persistentPostRun
function.NewExecutor()
in here thepersistentPostRun
function is configured asPersistentPostRunE
handler for CobraSo when linting is run in serial with other commands, golangci-lint exits the task pipeline too early with
os.exit
even when successful, and rest of the tasks are not run. Small (but not sure if relevant) detail is that in this context, golangci-lint is being used as a package library to not require users to install the CLI tool on the host, but using it as an utility library instead. Expected behavior is, that the serial command execution pipeline is exited early only when errors are encountered in the tasks in the pipeline, or finishes all the tasks with successful exit code.Version of golangci-lint
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
Sample repo with reproduction guide: https://github.com/kraashen/golangci-lint-mage-issue-sample
Validation
The text was updated successfully, but these errors were encountered: