{"id":"1ab3ecb8d6a952ac","repo":"gohugoio/hugo","slug":"failed-to-match-resource-with-metadata-w","errorCode":null,"errorMessage":"failed to match resource with metadata: %w","messagePattern":"failed to match resource with metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_metadata.go","lineNumber":166,"sourceCode":"func 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))\n\t\t\t\t\tif !nameCounterFound {\n\t\t\t\t\t\tnameCounterFound = strings.Contains(name, counterPlaceHolder)\n\t\t\t\t\t}\n\t\t\t\t\tif nameCounterFound && nameCounter == 0 {\n\t\t\t\t\t\tcounterKey := \"name_\" + srcKey\n\t\t\t\t\t\tnameCounter = counters[counterKey] + 1\n\t\t\t\t\t\tcounters[counterKey] = nameCounter","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/resource_metadata.go#L148-L184","documentation":"After reading a metadata entry's `src` value, Hugo compiles it into a glob via `hglob.GetGlob` to match against resource names. If the pattern is syntactically invalid (e.g. unbalanced brackets or braces), glob compilation fails and this error wraps the underlying glob parse error.","triggerScenarios":"A `resources` front-matter entry whose `src` is an invalid glob, e.g. `src: \"images/[jpg\"` or `src: \"{a,b\"`; triggered during resource metadata assignment for the bundle.","commonSituations":"Unescaped `[`, `]`, `{`, `}` in filenames used directly as `src`; copying regex syntax into a glob field; special characters in asset filenames from designers or exports.","solutions":["Fix the glob syntax in `src` — balance brackets/braces or escape literal special characters.","If the filename itself contains glob metacharacters, rename the file or use a broader pattern like `images/*`.","Test the pattern mentally against `filepath.Match`/gobwas-glob semantics: `*`, `**`, `?`, `[...]`, `{a,b}` are the supported constructs."],"exampleFix":"# before\nresources:\n- src: \"images/[header.jpg\"\n# after\nresources:\n- src: \"images/header.jpg\"","handlingStrategy":"validation","validationCode":"# validate the src glob is well-formed before building\n# bad: src = \"images/[.jpg\"  (invalid glob)\n# good: src = \"images/*.jpg\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use simple, valid glob patterns in resource metadata `src` (avoid unbalanced brackets).","Test globs against the bundle's actual files with `hugo --printPathWarnings` or a local build before deploying.","Keep resource filenames free of glob metacharacters, or escape them in the pattern."],"tags":["hugo","resources","glob","front-matter","metadata"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}