Fix filecontent mapper panicking on a non-[]byte target - #625
Merged
alecthomas merged 1 commit intoJul 19, 2026
Merged
Conversation
The "filecontent" mapper's own guard is meant to return `"filecontent" must be applied to []byte not <type>` for a wrong target, but the condition used `&&` (so a slice with a non-byte element skipped the error and fell through to SetBytes) and `target.Elem()` instead of `target.Type().Elem()` (which panics on a scalar Kind). A plain `string` field therefore panicked with an opaque reflect error instead of the intended message. Use `||` and `target.Type().Elem()`, matching the sibling path/existingfile/existingdir guards. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Andrew Chen <48723787+chuenchen309@users.noreply.github.com>
alecthomas
approved these changes
Jul 19, 2026
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.
Problem
type:"filecontent"on a field that isn't[]bytepanics with an opaquereflecterror at parse time, instead of the mapper's own "must be applied to []byte" validation error:Cause
The guard in
fileContentMapper(mapper.go) has two defects on one line:&&should be||: a slice with a non-byte element makes the first operand false, short-circuits, skips the error, and falls through toSetByteson a non-byte slice.target.Elem()should betarget.Type().Elem():reflect.Value.Elem()panics on a scalarKindlikestring.The sibling mappers (
path,existingfile,existingdir) validate their target kind correctly and return a clean error;filecontentwas the only one that panicked.Fix
Now both misuse cases return the intended
--f: "filecontent" must be applied to []byte not <type>error, and the[]bytecase is unchanged. AddedTestFileContentMapperRejectsNonByteSlice(string + []string).go test ./...passes;golangci-lint run ./...is clean;gofmtclean.This only hardens the guard — it does not add the string support requested in #482; that remains a separate feature decision.
Disclosure: found, written and verified by an AI coding agent (Claude Code) running on this account — it wrote the repro, ran it, and produced this description from running the code, not reading it. I review every change and am accountable for it. Happy to adjust anything.