{"record":{"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":"critical","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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource_metadata.go#L141-L177","documentation":"Returned by `assignMetadata` (resource_metadata.go:148-160) when iterating the resource `headless`/page-bundle metadata list and an entry has no `src` key. Every metadata rule must declare which resource(s) it targets via `src` (a glob, matched case-insensitively via `filepath.Match`). Missing `src` is treated as a config error because the rule would match nothing deterministically.","triggerScenarios":"A page bundle frontmatter / `_index.md` headless-resource metadata block where a `[[resources]]` (TOML) or `resources:` list item (YAML) omits `src`, e.g. only declares `name` or `title`. Reached via `assignMetadata` during resource metadata binding.","commonSituations":"YAML indentation making `src` a sibling rather than a list-item field; copy-paste of a metadata block dropping the `src` line; typo like `Src` (case-sensitive key lookup); TOML `[[resources]]` table missing `src`; refactor that renamed `src` to `path`/`match`.","solutions":["Add `src` to every metadata entry with a glob or filename matching the bundle's files.","In YAML, ensure `src` is a key under the list item (same indentation as `name`/`title`).","Use lowercase `src` (the key lookup is case-sensitive).","Validate each entry has `src`, `name`, and/or `title` before building."],"exampleFix":"# frontmatter -- before\nresources:\n  - name: hero\n    title: Hero image\n\n# after\nresources:\n  - src: images/hero*.jpg\n    name: hero\n    title: Hero image","handlingStrategy":"validation","validationCode":"// Validate page-bundle frontmatter metadata before build.\nfunc validateResourceMeta(meta []map[string]any) error {\n\tfor i, m := range meta {\n\t\tif _, ok := m[\"src\"]; !ok {\n\t\t\treturn fmt.Errorf(\"metadata entry %d missing 'src'\", i)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use lowercase `src` in every `[[resources]]` / `resources:` entry.","Keep `src`, `name`, `title` at the same YAML indentation.","Lint frontmatter with a schema checker in CI."],"tags":["resources","metadata","frontmatter","config","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}