Repository navigation
query: skip nil encoder interface fields instead of panicking - #197
Draft
rootkiller6788 wants to merge 2 commits into
Draft
rootkiller6788 wants to merge 2 commits into
rootkiller6788 wants to merge 2 commits into
Conversation
A struct field with an interface type that implements Encoder, left nil, falls through the interface unwrap (which only fires for non-nil values) and hits sv.Interface().(Encoder) on a nil interface, which panics with "interface conversion: interface is nil, not query.Encoder". Treat a nil encoder interface like any other empty value and skip the field.
Values() on a struct with a nil interface field that implements Encoder used to panic; the test locks in the skip behavior and confirms non-nil values still go through their custom encoder.
willnorris
approved these changes
Oct 19, 2026
willnorris
self-requested a review
October 19, 2026 21:26
Collaborator
|
(re-requested my own review, since I see it's still in draft. not sure if you were planning on doing more) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a struct has a field of an interface type that implements Encoder, and that field is left nil, Values() crashes:
That panic happens because the interface unwrap added for non-nil interfaces doesn't fire for a nil one, so we go straight into the Encoder block and call EncodeValues on a nil interface. There's no concrete encoder to call, so I skip the field the same way we skip other empty values. Non-nil values still get encoded normally.
Repro:
Added a regression test in query/encode_test.go.