{"id":"94a1c449a94e2c31","repo":"gohugoio/hugo","slug":"missing-src-in-metadata-for-resource","errorCode":null,"errorMessage":"missing 'src' in metadata for resource","messagePattern":"missing 'src' in metadata for resource","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_metadata.go","lineNumber":159,"sourceCode":"}\n\n// AssignMetadata assigns the given metadata to those resources that supports updates\n// and matching by wildcard given in `src` using `filepath.Match` with lower cased values.\n// This assignment is additive, but the most specific match needs to be first.\n// The `name` and `title` metadata field support shell-matched collection it got a match in.\n// See https://golang.org/pkg/path/#Match\nfunc assignMetadata(metadata []map[string]any, ma *metaResource, counters map[string]int) error {\n\tvar (\n\t\tnameSet, titleSet                   bool\n\t\tnameCounter, titleCounter           = 0, 0\n\t\tnameCounterFound, titleCounterFound bool\n\t\tresourceSrcKey                      = strings.ToLower(ma.Name())\n\t)\n\n\tfor _, meta := range metadata {\n\t\tsrc, found := meta[\"src\"]\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"missing 'src' in metadata for resource\")\n\t\t}\n\n\t\tsrcKey := strings.ToLower(cast.ToString(src))\n\n\t\tglob, err := hglob.GetGlob(srcKey)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to match resource with metadata: %w\", err)\n\t\t}\n\n\t\tmatch := glob.Match(resourceSrcKey)\n\n\t\tif match {\n\t\t\tif !nameSet {\n\t\t\t\tname, found := meta[\"name\"]\n\t\t\t\tif found {\n\t\t\t\t\tname := cast.ToString(name)\n\t\t\t\t\t// Bundled resources in sub folders are relative paths with forward slashes. Make sure any renames also matches that format:\n\t\t\t\t\tname = paths.TrimLeading(filepath.ToSlash(name))","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/resource_metadata.go#L141-L177","documentation":"When Hugo assigns metadata to page-bundle resources from the `resources` list in front matter, every metadata entry must contain a `src` key — the glob pattern that selects which resources it applies to. An entry without `src` cannot be matched to anything, so `assignMetadata` fails fast with this error.","triggerScenarios":"A page bundle's front matter has a `resources:` entry missing `src`, e.g. `resources: [{name: photo, title: Photo}]`; also hit via `CloneWithMetadataFromMapIfNeeded` for any resource in that bundle.","commonSituations":"Typos like `source:` or `path:` instead of `src`; YAML indentation errors that detach `src` from its list item; copying resource metadata examples incompletely.","solutions":["Add a `src` glob to every entry under `resources` in the page's front matter, e.g. `src: \"images/*.jpg\"` or `src: \"**\"` for all.","Check YAML/TOML indentation so `src` sits inside the same list item as `name`/`title`/`params`.","Rename mistaken keys (`source`, `path`, `file`) to `src`."],"exampleFix":"# before\nresources:\n- name: header\n  title: Header image\n# after\nresources:\n- src: \"images/header.jpg\"\n  name: header\n  title: Header image","handlingStrategy":"validation","validationCode":"# front matter: every resources entry needs a src glob\n[[resources]]\n  src = \"images/*.jpg\"   # required\n  title = \"Gallery :counter\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include a `src` key in every `[[resources]]` front matter block.","Lint bundles' front matter in CI (e.g. a script checking each resources entry has src).","Remember `src` matches paths relative to the page bundle, and an entry without it fails the whole build."],"tags":["hugo","resources","front-matter","page-bundles","metadata"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}