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

logcheck: do not error out if no Go files present #220

Closed
wants to merge 1 commit into from

Conversation

umangachapagain
Copy link

@umangachapagain umangachapagain commented Mar 8, 2021

What this PR does / why we need it:

Exit with code 0 when the provided package has no Go files
and code 1 for all other errors.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #214

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:

None.

Exit with code 0 when the provided package has no Go files
and code 1 for all other errors.

Signed-off-by: Umanga Chapagain <chapagainumanga@gmail.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 8, 2021
@k8s-ci-robot
Copy link

Welcome @umangachapagain!

It looks like this is your first PR to kubernetes/klog 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/klog has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: umangachapagain
To complete the pull request process, please assign brancz after the PR has been reviewed.
You can assign the PR to them by writing /assign @brancz in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 8, 2021
@umangachapagain
Copy link
Author

/cc @dims @nikhita

@dims
Copy link
Member

dims commented Mar 8, 2021

/assign @adisky

@@ -35,6 +38,7 @@ var Analyzer = &analysis.Analyzer{
}

func main() {
handleErrors()
singlechecker.Main(Analyzer)
Copy link

Choose a reason for hiding this comment

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

I think the error is coming from singlechecker.Main(Analyzer) and it is exiting with exit code 1 while package loading. singlechecker.Main(Analyzer) would be called anyways after handleErrors(), so it will fail?

Copy link
Author

Choose a reason for hiding this comment

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

handleErrors() will exit with code 0 for no Go files error and code 1 for all other errors. So singlechecker.Main(Analyzer) will never be called if there is an error while loading package.

I don't like this approach because we're duplicating what checker does. But, in current state that looks like the only way to me. We can discuss on other alternatives.

Copy link

Choose a reason for hiding this comment

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

I see, it might slow down the tool

Copy link
Author

Choose a reason for hiding this comment

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

Yeah but it's either that or we error out from the checker.

@adisky
Copy link

adisky commented Mar 15, 2021

The error is coming from singlechecker.Main(Analyzer)and it is exiting with os.Exit(1) while package loading without returning the error, We cannot handle the error as it is not returned. This way (this PR) It will reload packages two times and I think it might slow down the linter.

func main() {
singlechecker.Main(Analyzer)
}

cc @ehashman @serathius @navidshaikh do you have any suggestions here? or we should mark it as won't fix.

references for singlechecker package.
[1] https://github.com/golang/tools/blob/v0.1.0/go/analysis/singlechecker/singlechecker.go#L76
[2] https://github.com/golang/tools/blob/v0.1.0/go/analysis/internal/checker/checker.go#L130-L133

@umangachapagain
Copy link
Author

The error is coming from singlechecker.Main(Analyzer)and it is exiting with os.Exit(1) while package loading without returning the error, We cannot handle the error as it is not returned. This way (this PR) It will reload packages two times and I think it might slow down the linter.

func main() {
singlechecker.Main(Analyzer)
}

cc @ehashman @serathius @navidshaikh do you have any suggestions here? or we should mark it as won't fix.

references for singlechecker package.
[1] https://github.com/golang/tools/blob/v0.1.0/go/analysis/singlechecker/singlechecker.go#L76
[2] https://github.com/golang/tools/blob/v0.1.0/go/analysis/internal/checker/checker.go#L130-L133

We should probably mark it as won't fix.
While looking into this error, somewhere in the code comments I read that packages without Go files are not allowed and even go vet would return an error (code 1) if you pass such packages.

@ehashman
Copy link
Member

/retitle logcheck: do not error out if no Go files present

While looking into this error, somewhere in the code comments I read that packages without Go files are not allowed and even go vet would return an error (code 1) if you pass such packages.

The issue I filed doesn't suggest we try to load empty packages. I asked to ensure that we don't fail when we try to test an empty package, because an empty package can't possibly require a log migration. This is especially important for when we reverse the CI script's logic to fail any directory that isn't an explicitly allowed failure. We will have much less control over input at that point.

I suspect the best way to accomplish this may be to always return true if given a path that contains no Go files before starting the rest of the program logic. This would constitute input validation and is not the way the PR is currently written.

@k8s-ci-robot k8s-ci-robot changed the title do not error out if no Go files present logcheck: do not error out if no Go files present Mar 17, 2021
@umangachapagain
Copy link
Author

The issue I filed doesn't suggest we try to load empty packages. I asked to ensure that we don't fail when we try to test an empty package, because an empty package can't possibly require a log migration. This is especially important for when we reverse the CI script's logic to fail any directory that isn't an explicitly allowed failure. We will have much less control over input at that point.

I understand the issue doesn't suggest that we try to load empty packages. But, I don't know a way to find an empty package without trying to load it.

I suspect the best way to accomplish this may be to always return true if given a path that contains no Go files before starting the rest of the program logic. This would constitute input validation and is not the way the PR is currently written.

I have some questions. But, before I ask those I'd like to know your view on how we do this?

@k8s-ci-robot
Copy link

@umangachapagain: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 21, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 31, 2021
@umangachapagain
Copy link
Author

/close

@k8s-ci-robot
Copy link

@umangachapagain: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

logcheck: should not return error if no Go files are present
6 participants