Skip to content

Return an error for unsupported SetField targets - #27

Open
vitalivo wants to merge 1 commit into
oleiade:masterfrom
vitalivo:fix/set-field-invalid-target
Open

vitalivo wants to merge 1 commit into
oleiade:masterfrom
vitalivo:fix/set-field-invalid-target

Conversation

@vitalivo

Copy link
Copy Markdown

Related to #13.

SetField calls Elem() before checking its input, so a struct value, nil, or a pointer to a non-struct panics instead of returning an error. This contradicts its documented requirement that unsupported inputs fail, and differs from the error handling used by the other field helpers.

Validate that the target is a non-nil pointer to a struct before accessing its fields. Return an error wrapping ErrUnsupportedType for unsupported targets. Existing pointer-to-struct writes keep their behavior.

The regression test covers six unsupported target shapes; all six panic before the fix. Full go test -race -cover ./... passes (97.8% coverage), along with go vet ./... and staticcheck ./..., using Go 1.27.1.

@vitalivo vitalivo closed this Sep 12, 2026
@vitalivo vitalivo reopened this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant