-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 nil checking on typed interface #17598
Conversation
Gusted
commented
Nov 9, 2021
- Partially resoles Tracking issue: Updating golangci-lint #17596
- Resolves SA4023 errors.
- Ensure correctly that typed interface are nil.
- Partially resoles go-gitea#17596 - Resolves SA4023 errors. - Ensure correctly that typed interface are nil.
`NewBleveIndexer` will never return nil, even on errors.
According to https://staticcheck.io/docs/checks#SA4023 , I think these low-level functions(NewBleveIndexer, NewElasticSearchIndexer, session.GetSession) all did wrong, they didn't follow the Go language spec. We should fix the low-level code instead of using the IsInterfaceNil in my mind. (I think we should never use the reflection to check a nil, Go won't like it) |
Well, that's kind of the problem that this check is addressing - even if they will return So unless if the fix up is to do the
It's the only way to check if a typed interface is nil or actually a typed interface with data. |
Yes, I agree that is a problem. However the problems should be fixed from low-level code in my mind.
I can not quite understand why we can not fix
As long as the low-level code gets correct, we don't need it. For example, we never do IsInterfaceNil for |
Got it, I see what you're getting at - uno momento. For |
Ah, no, you shouldn't change code below |
Ah yes, sorry, after looking more careful, the session value should always be set, so the whole check is unnecessary. |
Codecov Report
@@ Coverage Diff @@
## main #17598 +/- ##
=======================================
Coverage ? 45.48%
=======================================
Files ? 799
Lines ? 88954
Branches ? 0
=======================================
Hits ? 40463
Misses ? 41994
Partials ? 6497
Continue to review full report at Codecov.
|
* Fix nil checking on typed interface - Partially resoles go-gitea#17596 - Resolves SA4023 errors. - Ensure correctly that typed interface are nil. * Remove unnecessary code `NewBleveIndexer` will never return nil, even on errors. * Patch `NewBleveIndexer` * Fix low-level functions * Remove deadcode * Fix GetSession * Close Elastic search when err isn't nil * Update elastic_search.go Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>