gohugoio/hugo · error

invalid strict mode; expected one of error, ignore, or…

Error message

invalid strict mode; expected one of error, ignore, or warn; received %s

What it means

The transform.ToMath function renders LaTeX via KaTeX with a Strict option. After decoding the options map into KatexOptions (transform.go:283-288), Hugo validates that Strict is exactly one of "error", "ignore", or "warn"; any other value is rejected before dispatching to the WASM KaTeX renderer. The default is "error".

Solutions

  1. Set strict to one of "error", "ignore", or "warn".
  2. Omit the strict option entirely to use the default "error".
  3. Double-check spelling — 'warn' not 'warning', 'ignore' not 'off'.

Example fix

// before
{{ transform.ToMath "x^2" (dict "strict" "warning") }}

// after
{{ transform.ToMath "x^2" (dict "strict" "warn") }}
Defensive patterns

Strategy: validation

Validate before calling

// Always pass one of: error, ignore, warn for the strict option:
{{ transform.ToMath $expr (dict "strict" "warn") }}
// Or omit it to default to "error".

Type guard

// In Go, before calling, validate the option:
func validStrict(s string) bool {
    switch s {
    case "", "error", "ignore", "warn":
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Calling {{ transform.ToMath "x^2" (dict "strict" "strict") }} or any value other than error/ignore/warn for the strict key. The switch falls through to the default branch.

Common situations: Passing "true"/"false" assuming boolean handling; passing "off" or a typo like "warning" instead of "warn"; copying KaTeX docs that use different strict values than Hugo exposes.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/0b294f88d8fda15e. Report an issue: GitHub.

Appendix: source

Thrown at tpl/transform/transform.go:287

			Output:           "mathml",
			MinRuleThickness: 0.04,
			ErrorColor:       "#cc0000",
			ThrowOnError:     true,
			Strict:           "error",
		},
	}

	if len(args) > 1 {
		if err := mapstructure.WeakDecode(args[1], &katexInput.Options); err != nil {
			return "", err
		}
	}

	switch katexInput.Options.Strict {
	case "error", "ignore", "warn":
		// Valid strict mode, continue
	default:
		return "", fmt.Errorf("invalid strict mode; expected one of error, ignore, or warn; received %s", katexInput.Options.Strict)
	}

	type fileCacheEntry struct {
		Version  string   `json:"version"`
		Output   string   `json:"output"`
		Warnings []string `json:"warnings,omitempty"`
	}

	const fileCacheEntryVersion = "v1" // Increment on incompatible changes.

	s := hashing.HashString(args...)
	key := "tomath/" + fileCacheEntryVersion + "/" + s[:2] + "/" + s[2:]
	fileCache := ns.deps.ResourceSpec.FileCaches.MiscCache()

	v, err := ns.cacheMath.GetOrCreate(key, func(string) (template.HTML, error) {
		_, r, err := fileCache.GetOrCreate(key, func() (io.ReadCloser, error) {
			message := warpc.Message[warpc.KatexInput]{
				Header: warpc.Header{

View on GitHub (pinned to 52c9bd7908)