tpl/collections: Include template path in IsSet unsupported type warning#14931
tpl/collections: Include template path in IsSet unsupported type warning#14931truffle-dev wants to merge 1 commit into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
8011559 to
a5189ed
Compare
When isset is called on a value that's not an array, channel, slice, or map, Hugo logs a warning that says only "calling IsSet with unsupported type X (Y) will always return false." On any site with more than one template, there's no way to find the offending call site. Thread context through IsSet and surface the executing template's filename in the warning. Switch from Log.Warnf to Log.Warnidf so the warning is grouped under an ID that users can suppress via ignoreLogs. Fixes gohugoio#11794
a5189ed to
8eab207
Compare
Fixes #11794
Summary
When
issetis called on a value that is not an array, channel, slice, or map, Hugo logs:On any site with more than one template there's no way to find the offending call site. The warning is also emitted via
Log.Warnf, so it has no ID and can't be silenced viaignoreLogs.This PR threads
context.ContextthroughIsSet, looks up the executing template viatpl.Context.CurrentTemplate.Get, and surfaces the filename in the warning. It also switchesLog.WarnftoLog.Warnidfwith a new constantWarnIsSetUnsupportedTypeso the warning is groupable and suppressible.After the change:
Changes
tpl/collections/collections.go—IsSetacceptsctx context.Contextas its first arg, matching the pattern used byDelimitand other ctx-aware namespace functions. The default branch resolves the current template and appendsin "<path>"to the warning, then routes throughLog.Warnidf.common/constants/constants.go— addsWarnIsSetUnsupportedType.tpl/collections/collections_test.go— passescontext.Background()to the existingTestIsSetcases.tpl/collections/collections_integration_test.go— adds a regression test asserting the template path appears in the warning.docs/data/docs.yaml— addsctxtoIsSet'sArgslist, matching the documented shape for other ctx-aware namespace functions.Tests
go test ./tpl/collections/... -run TestIsSet -v— unit and integration tests pass.go test ./tpl/collections/...— full package green.go vet ./tpl/collections/...— clean.gofmt -lon touched paths — clean.go build ./...— full tree builds.AI Assistance
I used AI assistance to investigate the issue, design the fix, and prepare tests. I reviewed the final diff, kept the scope narrow per CONTRIBUTING.md, and ran the checks listed above before opening.