-
Notifications
You must be signed in to change notification settings - Fork 1.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
Sanity check for empty variables #3021
Conversation
Empty variables have nil value and default type, this change adds sanity checks before the value is type asserted and cause panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r1.
Reviewable status: complete! all files reviewed, all discussions resolved
Val types use a field Value which is an interface. Type assertions of Value will panic when it is nil. The Safe() function will ensure a non-nil Value is returned. It won't change it, only make type assertions safer. Note that invalid type assertions are still possible.
A Val of type DefaultID could be a default value, play it safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r2.
Reviewable status: complete! all files reviewed, all discussions resolved
* types/sort.go: sanity check for empty variables Empty variables have nil value and default type, this change adds sanity checks before the value is type asserted and cause panic. * query/query.go: enhanced default value vars comment * types/scalar_types.go: added func Safe() Val types use a field Value which is an interface. Type assertions of Value will panic when it is nil. The Safe() function will ensure a non-nil Value is returned. It won't change it, only make type assertions safer. Note that invalid type assertions are still possible. * types/conversion.go: use Safe() in MarshalJSON() for DefaultID A Val of type DefaultID could be a default value, play it safe. * types/sort.go: use Safe() and narrow the field to DefaultID * types/sort.go: revert unneeded change
Empty variables have nil value and default type, this change
adds sanity checks before the value is type asserted and cause panic.
This change is