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

lint: enable errcheck and fix some issues #327

Merged
merged 2 commits into from
Sep 3, 2019

Conversation

ferhatelmas
Copy link
Contributor

@ferhatelmas ferhatelmas commented Sep 2, 2019

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 2, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 2, 2019
* add .errcheck-excluded.txt to disable some function calls
* related to kubernetes-sigs#325
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Sep 2, 2019
@ferhatelmas
Copy link
Contributor Author

I had added fixes keyword but it seems not allowed so changed it to related to.

@codecov-io
Copy link

codecov-io commented Sep 2, 2019

Codecov Report

Merging #327 into master will decrease coverage by 0.41%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
- Coverage    57.3%   56.89%   -0.42%     
==========================================
  Files          19       19              
  Lines         904      907       +3     
==========================================
- Hits          518      516       -2     
- Misses        335      338       +3     
- Partials       51       53       +2
Impacted Files Coverage Δ
pkg/download/downloader.go 65.71% <0%> (-1.6%) ⬇️
cmd/validate-krew-manifest/main.go 56.12% <0%> (-2.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 798fe49...9ee6a54. Read the comment docs.

flag.Set("logtostderr", "true") // Set glog default to stderr
// Set glog default to stderr
if err := flag.Set("logtostderr", "true"); err != nil {
glog.Fatal(err)
Copy link
Member

@ahmetb ahmetb Sep 2, 2019

Choose a reason for hiding this comment

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

I think it would be good to use fmt.Printf + os.Exit(1) here, as glog is currently not initialized probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated as suggested.

@corneliusweig
Copy link
Contributor

Looks good to me. Thanks for getting this done!

Have you tried changing the PR description from "related to #325" to "fixes #325"? I think it's only forbidden in commit messages but fine in PR descriptions.

Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

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

Looking at this a little more, I do not understand why some errors are not reported. For example, in pkg/receiptsmigration/migration_test.go:66 there is a Setenv call which returns an unhandled error that is not reported. On the other hand, the unhandled MkdirAll error in line 72 is reported. So what is the logic behind reporting some but not all errors?

@@ -0,0 +1,2 @@
os.MkdirAll
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it also be possible to explicitly ignore errors in the exact locations where we want to ignore errors. Like so:

_ = os.MkdirAll(...)

Copy link
Contributor Author

@ferhatelmas ferhatelmas Sep 3, 2019

Choose a reason for hiding this comment

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

definitely. Then we shouldn't have this file for the sake of being explicit all the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's possible. For being explicit, I dropped this file.

@ferhatelmas
Copy link
Contributor Author

ferhatelmas commented Sep 3, 2019

I think it's only forbidden in commit messages but fine in PR descriptions.

@corneliusweig updated and seems so. Thanks!

@@ -0,0 +1,2 @@
os.MkdirAll
Copy link
Member

Choose a reason for hiding this comment

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

since it's just 2 lines or possibly even 1, let's just drop this file if possible and call errcheck with --flags. it's kinda annoying to have an extra file in repo root just for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, dropped. Will push soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed.

@ferhatelmas
Copy link
Contributor Author

ferhatelmas commented Sep 3, 2019

Looking at this a little more, I do not understand why some errors are not reported. For example, in pkg/receiptsmigration/migration_test.go:66 there is a Setenv call which returns an unhandled error that is not reported. On the other hand, the unhandled MkdirAll error in line 72 is reported. So what is the logic behind reporting some but not all errors?

It seems a bug from golangci-lint. Even if errcheck reports it, golangci-lint doesn't report it. Reported at golangci/golangci-lint#657

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 3, 2019
@corneliusweig
Copy link
Contributor

/lgtm
waiting for @ahmetb to approve.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 3, 2019
@ahmetb
Copy link
Member

ahmetb commented Sep 3, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, ferhatelmas

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 3, 2019
@k8s-ci-robot k8s-ci-robot merged commit f7a36f5 into kubernetes-sigs:master Sep 3, 2019
@ferhatelmas ferhatelmas deleted the enable-errcheck branch September 5, 2019 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

Consider enabling errcheck linter
5 participants