{"id":"7f8cc043c7803483","repo":"gohugoio/hugo","slug":"style-q-does-not-have-a-q-mode","errorCode":null,"errorMessage":"style %q does not have a %q mode","messagePattern":"style %q does not have a %q mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"markup/highlight/chromastyles.go","lineNumber":72,"sourceCode":"\tname := strings.ToLower(opts.Style)\n\tif !slices.Contains(styles.Names(), name) {\n\t\treturn \"\", fmt.Errorf(\"invalid style: %s\", name)\n\t}\n\tvar chromaStyle *chroma.Style\n\tif opts.Mode != \"\" {\n\t\tvar mode chroma.Mode\n\t\tswitch opts.Mode {\n\t\tcase \"light\":\n\t\t\tmode = chroma.Light\n\t\tcase \"dark\":\n\t\t\tmode = chroma.Dark\n\t\tdefault:\n\t\t\treturn \"\", fmt.Errorf(\"invalid mode: %s\", opts.Mode)\n\t\t}\n\n\t\tchromaStyle = styles.GetForMode(name, mode)\n\t\tif chromaStyle.Mode() != mode {\n\t\t\treturn \"\", fmt.Errorf(\"style %q does not have a %q mode\", name, opts.Mode)\n\t\t}\n\t} else {\n\t\tchromaStyle = styles.Get(name)\n\t}\n\tbuilder := chromaStyle.Builder()\n\tif opts.HighlightStyle != \"\" {\n\t\tbuilder.Add(chroma.LineHighlight, opts.HighlightStyle)\n\t}\n\tif opts.LineNumbersInlineStyle != \"\" {\n\t\tbuilder.Add(chroma.LineNumbers, opts.LineNumbersInlineStyle)\n\t}\n\tif opts.LineNumbersTableStyle != \"\" {\n\t\tbuilder.Add(chroma.LineNumbersTable, opts.LineNumbersTableStyle)\n\t}\n\tstyle, err := builder.Build()\n\tif err != nil {\n\t\treturn \"\", err\n\t}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/markup/highlight/chromastyles.go#L54-L90","documentation":"After validating the mode string, Hugo asks Chroma for the style variant via `styles.GetForMode(name, mode)` and then checks that the returned style actually is in the requested mode. Many Chroma styles ship only a single (usually light) variant, so requesting e.g. the dark variant of a light-only style falls back to a style whose `Mode()` doesn't match, and Hugo fails fast rather than silently emitting the wrong palette.","triggerScenarios":"`hugo gen chromastyles --style=<name> --mode=<light|dark>` where the named Chroma style has no variant registered for that mode — e.g. asking for the \"dark\" mode of a light-only style like \"friendly\", or \"light\" for a dark-only style.","commonSituations":"Theme authors generating paired light/dark stylesheets for the class-based (`noClasses=false`) workflow and assuming every Chroma style has both variants; upgrading Chroma/Hugo and finding a style's mode support changed; copying a dual-mode build script between styles without checking mode availability.","solutions":["Pick a Chroma style that has the requested mode — pairs like \"github\"/\"github-dark\" or a style with registered light+dark variants.","Use two explicit styles (one per mode) instead of one style with two modes, generating each stylesheet separately.","Drop the mode option and let the style's native mode be used."],"exampleFix":"# before\nhugo gen chromastyles --style=friendly --mode=dark\n# after\nhugo gen chromastyles --style=github-dark --mode=dark","handlingStrategy":"validation","validationCode":"if styles.Get(styleName) == nil {\n    return fmt.Errorf(\"unknown chroma style %q\", styleName)\n}\n// then check the style actually declares the requested mode variant before use","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the style name exists in chroma's registry (styles.Names()) before requesting a mode-specific variant","Only request light/dark variants for styles documented to ship both modes","Fail fast at config-load time rather than at render time"],"tags":["hugo","chroma","syntax-highlighting","dark-mode","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}