{"id":"f986e8ff26d2a15e","repo":"gohugoio/hugo","slug":"startlevel-w","errorCode":null,"errorMessage":"startLevel: %w","messagePattern":"startLevel: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"markup/tableofcontents/tableofcontents.go","lineNumber":158,"sourceCode":"\n\tfor i := 1; i < level; i++ {\n\t\tif len(heading.Headings) == 0 {\n\t\t\theading.Headings = append(heading.Headings, &Heading{})\n\t\t}\n\t\theading = heading.Headings[len(heading.Headings)-1]\n\t}\n\theading.Headings = append(heading.Headings, h)\n}\n\n// ToHTML renders the ToC as HTML.\nfunc (toc *Fragments) ToHTML(startLevel, stopLevel any, ordered bool) (template.HTML, error) {\n\tif toc == nil {\n\t\treturn \"\", nil\n\t}\n\n\tiStartLevel, err := cast.ToIntE(startLevel)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"startLevel: %w\", err)\n\t}\n\n\tiStopLevel, err := cast.ToIntE(stopLevel)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"stopLevel: %w\", err)\n\t}\n\n\tb := &tocBuilder{\n\t\ts:          strings.Builder{},\n\t\th:          toc.Headings,\n\t\tstartLevel: iStartLevel,\n\t\tstopLevel:  iStopLevel,\n\t\tordered:    ordered,\n\t}\n\tb.Build()\n\treturn template.HTML(b.s.String()), nil\n}\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/markup/tableofcontents/tableofcontents.go#L140-L176","documentation":"`Fragments.ToHTML` renders a page's table of contents and accepts `startLevel` as `any`, casting it to int with `cast.ToIntE`. If the value passed from a template can't be coerced to an integer, the cast error is wrapped with the \"startLevel:\" prefix and the TableOfContents rendering fails for that page.","triggerScenarios":"A template calling the internal ToC rendering (e.g. via `.TableOfContents` machinery or a partial passing options) with a non-numeric startLevel — a string like \"h2\", a map, nil-ish template value, or a misconfigured `markup.tableOfContents.startLevel` fed through as a non-castable type.","commonSituations":"Setting `markup.tableOfContents.startLevel` to a non-numeric string in site config; theme partials that compute the level from front matter and pass an empty or malformed value; confusing heading names (\"h2\") with numeric levels (2).","solutions":["Pass a plain integer (or numeric string) for startLevel, e.g. 2 — heading level numbers, not \"h2\".","Check markup.tableOfContents.startLevel in site config is an integer between 1 and 6.","Trace the theme partial/front-matter value feeding the ToC call and coerce or default it before rendering."],"exampleFix":"# before (hugo.toml)\n[markup.tableOfContents]\nstartLevel = \"h2\"\n# after\n[markup.tableOfContents]\nstartLevel = 2","handlingStrategy":"validation","validationCode":"if toc.StartLevel < 1 || toc.StartLevel > 6 {\n    return fmt.Errorf(\"markup.tableOfContents.startLevel must be 1-6, got %d\", toc.StartLevel)\n}\nif toc.EndLevel != -1 && toc.EndLevel < toc.StartLevel {\n    return fmt.Errorf(\"endLevel %d must be >= startLevel %d\", toc.EndLevel, toc.StartLevel)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep markup.tableOfContents.startLevel within heading range (1-6) and as an integer, not a string","Ensure endLevel >= startLevel when both are set","Validate config changes with a local `hugo` build before committing"],"tags":["hugo","table-of-contents","templates","type-cast","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}