{"record":{"id":"846e5852bbbd0f81","repo":"gohugoio/hugo","slug":"invalid-path-q","errorCode":null,"errorMessage":"invalid path %q","messagePattern":"invalid path %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/pagesfromdata/pagesfromgotmpl.go","lineNumber":74,"sourceCode":"\t// The return value will always be an empty string.\n\tEnableAllLanguages() string\n}\n\nvar _ PagesFromDataTemplateContext = (*pagesFromDataTemplateContext)(nil)\n\ntype pagesFromDataTemplateContext struct {\n\tp *PagesFromTemplate\n}\n\nfunc (p *pagesFromDataTemplateContext) toPathSitesMap(v any) (string, map[string]any, map[string]any, error) {\n\tm, err := hmaps.ToStringMapE(v)\n\tif err != nil {\n\t\treturn \"\", nil, nil, err\n\t}\n\n\tpath, err := cast.ToStringE(m[\"path\"])\n\tif err != nil {\n\t\treturn \"\", nil, nil, fmt.Errorf(\"invalid path %q\", path)\n\t}\n\n\tsites := hmaps.ToStringMap(m[\"sites\"])\n\n\treturn path, sites, m, nil\n}\n\nfunc (p *pagesFromDataTemplateContext) AddPage(v any) (string, error) {\n\tpath, sites, m, err := p.toPathSitesMap(v)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\thash, hasChanged := p.p.buildState.checkHasChangedAndSetSourceInfo(path, sites, m)\n\tif !hasChanged {\n\t\treturn \"\", nil\n\t}\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/pagesfromdata/pagesfromgotmpl.go#L56-L92","documentation":"Raised by pagesFromDataTemplateContext.toPathSitesMap (pagesfromgotmpl.go:74) when the `path` field of the map passed to AddPage/AddResource cannot be converted to a string by cast.ToStringE. The path field is mandatory for pages created from a _content.gotmpl content adapter.","triggerScenarios":"Calling `AddPage` in a _content.gotmpl template with a map that omits `path` or sets it to a non-string (number, slice, map, bool). The cast fails and the invalid (often empty) path value is reported.","commonSituations":"Building a content adapter and forgetting the path key; passing a path computed from a numeric ID without converting to string; typos like `Path` (capitalized) instead of `path`.","solutions":["Ensure the map passed to AddPage contains a `path` key whose value is a string.","Convert non-string sources explicitly: `printf \"/posts/%d.md\" .ID`.","Use the lowercase key `path` exactly (map keys are case-sensitive here)."],"exampleFix":"{{/* before */}}\n{{ .AddPage (dict \"Path\" \"foo.md\" \"title\" \"Foo\") }}\n\n{{/* after */}}\n{{ .AddPage (dict \"path\" \"/foo.md\" \"title\" \"Foo\") }}","handlingStrategy":"validation","validationCode":null,"typeGuard":"{{/* In _content.gotmpl, validate path before AddPage */}}\n{{ $path := .path }}\n{{ if and $path (reflect.IsMap .) }}\n  {{ .AddPage (dict \"path\" (printf \"/%s\" $path) \"title\" .title) }}\n{{ else }}\n  {{ warnf \"AddPage requires a string 'path'\" }}\n{{ end }}","tryCatchPattern":null,"preventionTips":["Always pass a lowercase `path` string key (not `Path`) in AddPage/AddResource maps.","When generating paths from non-string IDs, convert with printf.","Keep a single helper that builds the AddPage map so the shape is consistent."],"tags":["content-adapter","gotmpl","type-mismatch"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}