{"id":"8ad237e562533764","repo":"gohugoio/hugo","slug":"content-source-failed-to-convert-t-to-string-s","errorCode":null,"errorMessage":"content source: failed to convert %T to string: %s","messagePattern":"content source: failed to convert %T to string: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/page/pagemeta/page_frontmatter.go","lineNumber":560,"sourceCode":"\tValue any\n}\n\nfunc (s Source) IsZero() bool {\n\treturn !hreflect.IsTruthful(s.Value)\n}\n\nfunc (s Source) IsResourceValue() bool {\n\t_, ok := s.Value.(resource.Resource)\n\treturn ok\n}\n\nfunc (s Source) ValueAsString() string {\n\tif s.Value == nil {\n\t\treturn \"\"\n\t}\n\tss, err := cast.ToStringE(s.Value)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"content source: failed to convert %T to string: %s\", s.Value, err))\n\t}\n\treturn ss\n}\n\nfunc (s Source) ValueAsOpenReadSeekCloser() hugio.OpenReadSeekCloser {\n\tcontent := s.ValueAsString()\n\treturn func() (hugio.ReadSeekCloser, error) {\n\t\treturn hugio.NewReadSeekerNoOpCloserFromString(content), nil\n\t}\n}\n\n// FrontMatterOnlyValues holds values that can only be set via front matter.\ntype FrontMatterOnlyValues struct {\n\tResourcesMeta []map[string]any\n}\n\n// FrontMatterHandler maps front matter into Page fields and .Params.\n// Note that we currently have only extracted the date logic.","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/page/pagemeta/page_frontmatter.go#L542-L578","documentation":"`Source.ValueAsString` in page_frontmatter.go casts the front matter `content.value` to a string with `cast.ToStringE` and **panics** with this message when the value is not string-convertible. It's a panic, not a returned error, because callers such as `ValueAsOpenReadSeekCloser` treat the content as already-validated. The `%T` shows the actual Go type Hugo received from the decoded front matter.","triggerScenarios":"Setting a page resource's `content.value` to a map, slice/array, or arbitrary struct instead of a scalar — e.g. a YAML block that parses as a nested mapping or a list — and then having Hugo read that resource's content (via `.Content`, `.ReadSeekCloser`, or publishing it).","commonSituations":"YAML indentation errors that turn an intended multi-line string into a nested map or sequence; TOML arrays used for multi-line content; passing a `resource.Resource` or a template-produced dict into `content.value` when a literal string was intended (note `IsResourceValue` handles genuine Resource values, so this panic means an unsupported third type).","solutions":["Make `content.value` a scalar string — use a YAML block scalar (`value: |`) or TOML multi-line `\"\"\"` literal instead of a nested structure.","Check the reported `%T` in the panic: `map[string]interface {}` or `[]interface {}` means the front matter parsed as a structure, so fix the indentation/quoting.","If you meant to reference an existing resource, assign the resource object itself so `IsResourceValue` matches, rather than a wrapper map.","Reproduce with a minimal page and `hugo --logLevel debug` to identify which page's front matter carries the bad value."],"exampleFix":"# before — YAML parses as a map, panics\nresources:\n  - name: intro\n    content:\n      value:\n        title: Hello\n\n# after — scalar string\nresources:\n  - name: intro\n    content:\n      value: |\n        title: Hello","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// ensure content source value is a string (or fmt.Stringer) before assigning\nfunc isStringable(v any) bool {\n    switch v.(type) {\n    case string, fmt.Stringer, []byte:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["In content adapters, pass content.value as a string, not a map/slice/number","Convert non-string values explicitly (e.g. with printf/string) before setting page content","Validate the shape of externally-sourced data (JSON APIs) before feeding it to AddPage"],"tags":["hugo","front-matter","panic","type-conversion","page-resources"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}