{"record":{"id":"3310160661622736","repo":"gohugoio/hugo","slug":"permalinks-failed-to-decode-target-w","errorCode":null,"errorMessage":"permalinks: failed to decode target: %w","messagePattern":"permalinks: failed to decode target: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/permalinks.go","lineNumber":543,"sourceCode":"\t\treturn decodePermalinksMap(v)\n\tdefault:\n\t\tif ms, err := hmaps.ToSliceStringMap(in); err == nil {\n\t\t\t// New slice format.\n\t\t\treturn decodePermalinksSlice(ms)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"permalinks: unsupported config type %T\", in)\n\t}\n}\n\nfunc decodePermalinksSlice(ms []map[string]any) (PermalinksConfig, error) {\n\tvar configs PermalinksConfig\n\tfor _, m := range ms {\n\t\tm = hmaps.CleanConfigStringMap(m)\n\t\tvar cfg PermalinkConfig\n\n\t\tif targetVal, ok := m[\"target\"]; ok {\n\t\t\tif err := mapstructure.WeakDecode(targetVal, &cfg.Target); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"permalinks: failed to decode target: %w\", err)\n\t\t\t}\n\t\t\tcfg.Target.Kind = strings.ToLower(cfg.Target.Kind)\n\t\t\tcfg.Target.Path = filepath.ToSlash(strings.ToLower(cfg.Target.Path))\n\t\t}\n\n\t\tif patternVal, ok := m[\"pattern\"]; ok {\n\t\t\tcfg.Pattern, ok = patternVal.(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"permalinks: pattern must be a string, got %T\", patternVal)\n\t\t\t}\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"permalinks: missing pattern\")\n\t\t}\n\n\t\tconfigs = append(configs, cfg)\n\t}\n\n\treturn configs, nil","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/page/permalinks.go#L525-L561","documentation":"Thrown by decodePermalinksSlice when mapstructure.WeakDecode of a rule's 'target' value into the PageMatcher struct fails. The wrapped error is the decode failure, so the target object's fields do not fit the PageMatcher schema (kind, path, language, environment, sites, etc.).","triggerScenarios":"A list-format permalink rule whose 'target' has wrong field types, e.g. target = { kind = 123 } (int instead of string) or target = \"/posts/**\" (string instead of a map).","commonSituations":"Migrating from the map format to the new slice format and writing target as a plain string path, or typos in target field names/types.","solutions":["Make 'target' a map with string-valued fields (kind, path, language, environment, sites).","Move a path-only target string into target = { path = \"/posts/**\" }.","Check the wrapped error for the specific field that failed to decode."],"exampleFix":"# before\n[[permalinks]]\ntarget = \"/posts/**\"\npattern = \"/:year/:slug/\"\n# after\n[[permalinks]]\ntarget = { path = \"/posts/**\" }\npattern = \"/:year/:slug/\"","handlingStrategy":"validation","validationCode":"if tv, ok := m[\"target\"]; ok {\n    if err := mapstructure.WeakDecode(tv, &page.PageMatcher{}); err != nil {\n        return fmt.Errorf(\"target shape invalid: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"cfg, err := page.DecodePermalinksConfig(raw)\nif err != nil { /* fix the offending target object */ }","preventionTips":["Write 'target' as a map with string-valued fields.","Put path-only targets in target = { path = \"...\" }.","Check the wrapped error for the failing field."],"tags":["hugo","permalinks","configuration","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}