{"record":{"id":"f673d9e7dc6778f5","repo":"gohugoio/hugo","slug":"config-needs-a-filename","errorCode":null,"errorMessage":"config needs a filename","messagePattern":"config needs a filename","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/images/images.go","lineNumber":79,"sourceCode":"// Namespace provides template functions for the \"images\" namespace.\ntype Namespace struct {\n\t*images.Filters\n\treadFileFs   afero.Fs\n\tcache        *maphelpers.ConcurrentMap[string, image.Config]\n\tdeps         *deps.Deps\n\tcreateClient *create.Client\n}\n\n// Config returns the image.Config for the specified path relative to the\n// working directory.\nfunc (ns *Namespace) Config(path any) (image.Config, error) {\n\tfilename, err := cast.ToStringE(path)\n\tif err != nil {\n\t\treturn image.Config{}, err\n\t}\n\n\tif filename == \"\" {\n\t\treturn image.Config{}, errors.New(\"config needs a filename\")\n\t}\n\n\treturn ns.cache.GetOrCreate(filename, func() (image.Config, error) {\n\t\tf, err := ns.readFileFs.Open(filename)\n\t\tif err != nil {\n\t\t\treturn image.Config{}, err\n\t\t}\n\t\tdefer f.Close()\n\n\t\text := filepath.Ext(filename)\n\t\tformat, _ := images.ImageFormatFromExt(ext)\n\n\t\tconfig, _, err := ns.deps.ResourceSpec.Imaging.Codec.DecodeConfig(format, f)\n\t\treturn config, err\n\t})\n}\n\n// Filter applies the given filters to the image given as the last element in args.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/images/images.go#L61-L97","documentation":"The `images.Config` function reads and decodes an image file to return its `image.Config` (dimensions, color type). After casting the argument to a string, if it is empty the function cannot locate a file and rejects the call at images.go:78–79.","triggerScenarios":"Calling `{{ (images.Config \"\") }}` or passing a template variable that resolves to an empty string, e.g. `{{ (images.Config .MissingPath) }}`.","commonSituations":"A front matter field or Scratch variable intended to hold an image path is unset, yielding an empty string. The developer expects a nil/zero config but gets an explicit error.","solutions":["Pass a valid relative path: `{{ (images.Config \"images/logo.png\") }}`.","Guard with a conditional: `{{ with $path }}{{ (images.Config .) }}{{ end }}`.","Verify the path variable is non-empty before the call."],"exampleFix":"// before\n{{ (images.Config .MaybeEmptyPath) }}\n// after\n{{ with .MaybeEmptyPath }}{{ (images.Config .) }}{{ end }}","handlingStrategy":"validation","validationCode":"{{ with $path }}{{ (images.Config .) }}{{ end }}","typeGuard":"func isNonEmptyString(v any) bool {\n    s, ok := v.(string)\n    return ok && s != \"\"\n}","tryCatchPattern":null,"preventionTips":["Guard the path with `{{ with }}` before calling images.Config.","Verify front matter image fields are non-empty.","Default to a known-good path when the field may be absent."],"tags":["hugo","template","images","config","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}