Skip to content

tpl/collections: Include template path in IsSet unsupported type warning#14931

Open
truffle-dev wants to merge 1 commit into
gohugoio:masterfrom
truffle-dev:fix-isset-warning-template-path
Open

tpl/collections: Include template path in IsSet unsupported type warning#14931
truffle-dev wants to merge 1 commit into
gohugoio:masterfrom
truffle-dev:fix-isset-warning-template-path

Conversation

@truffle-dev

Copy link
Copy Markdown

Fixes #11794

Summary

When isset is called on a value that is not an array, channel, slice, or map, Hugo logs:

WARN  calling IsSet with unsupported type "string" (string) will always return false.

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 via ignoreLogs.

This PR threads context.Context through IsSet, looks up the executing template via tpl.Context.CurrentTemplate.Get, and surfaces the filename in the warning. It also switches Log.Warnf to Log.Warnidf with a new constant WarnIsSetUnsupportedType so the warning is groupable and suppressible.

After the change:

WARN  calling IsSet with unsupported type "string" (string) in "/layouts/home.html" will always return false.
You can suppress this message by adding the following to your site configuration:
ignoreLogs = ['warning-isset-unsupported-type']

Changes

  • tpl/collections/collections.goIsSet accepts ctx context.Context as its first arg, matching the pattern used by Delimit and other ctx-aware namespace functions. The default branch resolves the current template and appends in "<path>" to the warning, then routes through Log.Warnidf.
  • common/constants/constants.go — adds WarnIsSetUnsupportedType.
  • tpl/collections/collections_test.go — passes context.Background() to the existing TestIsSet cases.
  • tpl/collections/collections_integration_test.go — adds a regression test asserting the template path appears in the warning.
  • docs/data/docs.yaml — adds ctx to IsSet's Args list, 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 -l on 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.

@gemini-code-assist

Copy link
Copy Markdown
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@CLAassistant

CLAassistant commented May 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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
@truffle-dev truffle-dev force-pushed the fix-isset-warning-template-path branch from a5189ed to 8eab207 Compare May 28, 2026 19:11
@truffle-dev

Copy link
Copy Markdown
Author

Hi @bep — small focused fix against #11794 (open since 2023), ~13 days idle. Happy to rebase or adjust the warning message if anything looks off. No rush, just keeping it on your radar.

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.

Warning about "IsSet with unsupported type" is not helpful

4 participants