-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Encapsulate Nil Checks #9454
Comments
It would be neat to have a [dream] |
I can try to do that (if that is not uber urgent and doesn't have to be delivered very fast) |
@pgagala I think it would be nice if we could do this incrementally, package by package or so. One huge PR will be very hard to maintain, especially merging with |
I think that is a good idea |
so far I was able to introduce some changes https://github.com/pgagala/prysm/tree/encapsulate-nil-checks-9454 |
I would gladly take over if that's a possibility. I can finish the beacon-chain package and make a PR for it. Then move on to the next package. |
Sounds good. Thanks for your help. I will also recommend to do it per beacon-chain sub package (ie blockchain, rpc.. etc). beacon-chain itself is an enormous package |
See https://github.com/prysmaticlabs/prysm/pull/9976/files#diff-867448a2b93d350184511d77435350937f71ea1ac154cefa13cdb3ce2bce26daR1 for an awesome pattern on how to do this ! |
💎 Issue
Background
One pattern we should opt for across our repo is to rely more on package-level errors rather than putting the burden of nil checks in certain situations on the caller. For example, a common pattern seen across the codebase is this:
One time, there was a PR with a bug because we forgot to add a nil check. Another time, there was another failure because we forgot state needs two nil checks. Pushing this check onto callers increases the probability. Go is already notorious for nil checks, which are risky if forgotten. Instead, we should aim to encapsulate them as much as possible and rely on error values as a sane alternative.
For example:
Notes
It is important to audit all uses of this nil encapsulation we are changing, however, as it is possible we introduce a bug in doing so. For example, some code paths might rely on error checking differently, and we may need to handle those error values in a sane manner. Additionally, some other code paths might actually rely on nil values returned from the db method to branch into certain execution. We should be careful with this change.
The text was updated successfully, but these errors were encountered: