{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/images/images.go#L61-L97","documentation":"`images.Config` reads the dimensions of an image file at a path relative to the working directory. After casting the argument to a string, Hugo checks it is non-empty; an empty filename cannot be opened, so it fails fast with this error rather than passing an empty path to the filesystem.","triggerScenarios":"Calling `{{ images.Config \"\" }}` or `{{ imageConfig $path }}` where `$path` evaluates to an empty string (e.g. a missing front matter field or unset variable).","commonSituations":"Front matter field like `.Params.image` missing on some pages while the template unconditionally calls `imageConfig`; a `default` fallback that resolves to empty; typoed variable names that silently evaluate empty.","solutions":["Guard the call: `{{ with .Params.image }}{{ $cfg := imageConfig . }}...{{ end }}`.","Verify the front matter or data source actually sets the image path on every page using the template.","Prefer page/global resources (`.Resources.Get` / `resources.Get`) and `.Width`/`.Height`, which handle missing files more idiomatically."],"exampleFix":"<!-- before -->\n{{ $cfg := imageConfig .Params.image }}\n<!-- after -->\n{{ with .Params.image }}\n  {{ $cfg := imageConfig . }}\n  {{ $cfg.Width }}x{{ $cfg.Height }}\n{{ end }}","handlingStrategy":"validation","validationCode":"{{ $file := \"config.json\" }}\n{{ if $file }}{{ $cfg := images.Config (printf \"exif/%s\" $file) }}{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a non-empty filename string to images.Config","Guard variables that may be empty (front matter, params) with `with` before calling","Verify the path points at an actual image under assets/ or static/"],"tags":["hugo","templates","images","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}