{"id":"0b294f88d8fda15e","repo":"gohugoio/hugo","slug":"invalid-strict-mode-expected-one-of-error-ignore","errorCode":null,"errorMessage":"invalid strict mode; expected one of error, ignore, or warn; received %s","messagePattern":"invalid strict mode; expected one of error, ignore, or warn; received (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/transform.go","lineNumber":287,"sourceCode":"\t\t\tOutput:           \"mathml\",\n\t\t\tMinRuleThickness: 0.04,\n\t\t\tErrorColor:       \"#cc0000\",\n\t\t\tThrowOnError:     true,\n\t\t\tStrict:           \"error\",\n\t\t},\n\t}\n\n\tif len(args) > 1 {\n\t\tif err := mapstructure.WeakDecode(args[1], &katexInput.Options); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tswitch katexInput.Options.Strict {\n\tcase \"error\", \"ignore\", \"warn\":\n\t\t// Valid strict mode, continue\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid strict mode; expected one of error, ignore, or warn; received %s\", katexInput.Options.Strict)\n\t}\n\n\ttype fileCacheEntry struct {\n\t\tVersion  string   `json:\"version\"`\n\t\tOutput   string   `json:\"output\"`\n\t\tWarnings []string `json:\"warnings,omitempty\"`\n\t}\n\n\tconst fileCacheEntryVersion = \"v1\" // Increment on incompatible changes.\n\n\ts := hashing.HashString(args...)\n\tkey := \"tomath/\" + fileCacheEntryVersion + \"/\" + s[:2] + \"/\" + s[2:]\n\tfileCache := ns.deps.ResourceSpec.FileCaches.MiscCache()\n\n\tv, err := ns.cacheMath.GetOrCreate(key, func(string) (template.HTML, error) {\n\t\t_, r, err := fileCache.GetOrCreate(key, func() (io.ReadCloser, error) {\n\t\t\tmessage := warpc.Message[warpc.KatexInput]{\n\t\t\t\tHeader: warpc.Header{","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/transform/transform.go#L269-L305","documentation":"`transform.ToMath` renders LaTeX with KaTeX and accepts an options map including `strict`, which controls how KaTeX handles non-standard LaTeX. Hugo validates that `strict` is exactly `error` (the default), `ignore`, or `warn`, and rejects any other value after weak-decoding the options.","triggerScenarios":"Calling `{{ transform.ToMath $expr (dict \"strict\" \"true\") }}` or any `strict` value outside error/ignore/warn — e.g. booleans, `\"strict\"`, `\"off\"`, or KaTeX-JS function-style values.","commonSituations":"Assuming `strict` is a boolean like in KaTeX's JS API (where `strict: false` is valid); typos or capitalized values; copying KaTeX docs that use a handler function, which Hugo's embedded KaTeX doesn't accept.","solutions":["Set strict to one of the exact strings: `error`, `ignore`, or `warn`.","Translate boolean intent: `strict: false` in KaTeX JS ≈ `\"ignore\"`; `strict: true` ≈ `\"error\"`.","Omit the option to keep the default `error` mode."],"exampleFix":"<!-- before -->\n{{ transform.ToMath .Inner (dict \"strict\" false) }}\n<!-- after -->\n{{ transform.ToMath .Inner (dict \"strict\" \"ignore\") }}","handlingStrategy":"validation","validationCode":"{{ $strict := .Params.strictMode | default \"error\" }}\n{{ if not (in (slice \"error\" \"ignore\" \"warn\") $strict) }}\n  {{ errorf \"strict must be error|ignore|warn, got %q\" $strict }}\n{{ end }}\n{{ $out := transform.ToMath $expr (dict \"strict\" $strict) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only \"error\", \"ignore\", or \"warn\" are valid strict-mode values for transform.ToMath","Whitelist-validate values coming from front matter or site params","Keep the value lowercase; don't pass booleans or other types"],"tags":["hugo","templates","transform","tomath","katex","options"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}