{"id":"f41181f2cabb2c31","repo":"gohugoio/hugo","slug":"invalid-mode-s","errorCode":null,"errorMessage":"invalid mode: %s","messagePattern":"invalid mode: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"markup/highlight/chromastyles.go","lineNumber":67,"sourceCode":"}\n\n// ChromaStylesCSS generates a CSS stylesheet for the Chroma code highlighter.\n// This stylesheet is needed if markup.highlight.noClasses is disabled in config.\nfunc ChromaStylesCSS(opts ChromaStylesOptions) (string, error) {\n\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)","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/markup/highlight/chromastyles.go#L49-L85","documentation":"Returned by `ChromaStylesCSS` in Hugo when generating a Chroma syntax-highlighting stylesheet with an explicit `Mode` option that is neither \"light\" nor \"dark\". The function maps the mode string to a `chroma.Mode` constant and rejects anything else before looking up the style variant.","triggerScenarios":"Calling `hugo gen chromastyles` (or the internal `transform.ToCSS`/chromastyles path) with a mode flag/option set to something other than the literal strings \"light\" or \"dark\", e.g. `--mode Dark`, `--mode auto`, or a typo like \"drak\". An empty mode is fine; only a non-empty, non-light/dark value fails.","commonSituations":"Users of Hugo's newer light/dark dual-stylesheet workflow passing capitalized values (\"Light\", \"DARK\") since the switch is case-sensitive, scripting `hugo gen chromastyles` from a theme build pipeline with an interpolated variable that resolves to an unexpected value, or guessing values like \"auto\"/\"both\" from other tools' conventions.","solutions":["Set the mode to exactly \"light\" or \"dark\" (lowercase).","If you don't need mode-specific output, omit the mode option entirely so the style's default variant is used.","Check the shell/CI variable feeding the flag isn't empty-quoted or misspelled."],"exampleFix":"# before\nhugo gen chromastyles --style=github --mode=Dark\n# after\nhugo gen chromastyles --style=github --mode=dark","handlingStrategy":"validation","validationCode":"validModes := map[string]bool{\"light\": true, \"dark\": true}\nif !validModes[mode] {\n    return fmt.Errorf(\"unsupported chroma style mode %q\", mode)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict mode input to a known enum (light/dark) before calling chroma style generation","Normalize user input with strings.ToLower and trim whitespace first","Surface allowed values in your CLI/config docs so users don't guess"],"tags":["hugo","chroma","syntax-highlighting","cli","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}