{"record":{"id":"6e17c7cc2d3e7a82","repo":"gohugoio/hugo","slug":"failed-to-encode-file-cache-entry-w","errorCode":null,"errorMessage":"failed to encode file cache entry: %w","messagePattern":"failed to encode file cache entry: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/transform/transform.go","lineNumber":331,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tresult, err := k.Execute(ctx, message)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\te := fileCacheEntry{\n\t\t\t\tVersion:  fileCacheEntryVersion,\n\t\t\t\tOutput:   result.Data.Output,\n\t\t\t\tWarnings: result.Header.Warnings,\n\t\t\t}\n\n\t\t\tbuf := &bytes.Buffer{}\n\t\t\tenc := json.NewEncoder(buf)\n\t\t\tenc.SetEscapeHTML(false)\n\t\t\tif err := enc.Encode(e); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to encode file cache entry: %w\", err)\n\t\t\t}\n\t\t\treturn hugio.NewReadSeekerNoOpCloserFromBytes(buf.Bytes()), nil\n\t\t})\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\tvar e fileCacheEntry\n\t\tif err := json.NewDecoder(r).Decode(&e); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to decode file cache entry: %w\", err)\n\t\t}\n\n\t\tfor _, warning := range e.Warnings {\n\t\t\tns.deps.Log.Warnf(\"transform.ToMath: %s\", warning)\n\t\t}\n\n\t\treturn template.HTML(e.Output), err\n\t})","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/transform/transform.go#L313-L349","documentation":"transform.ToMath caches rendered output to Hugo's misc file cache. After computing a result it JSON-encodes a fileCacheEntry (version, output, warnings) into the cache (transform.go:327-332). If json.Encoder.Encode fails — e.g. due to an unencodable value inside the result — the error wraps the encoding failure. Encoding a simple struct should not normally fail.","triggerScenarios":"The KaTeX WASM result contains data that cannot be JSON-serialized into the fileCacheEntry struct (e.g. a non-string in Output/Warnings). This is an internal/cache-layer failure during ToMath.","commonSituations":"Very rare; would indicate a Hugo/WASM protocol regression producing malformed KatexOutput. Could appear if the file cache is on a read-only or full filesystem where the write fails upstream — though that surfaces differently.","solutions":["Clear the Hugo cache (--gc or remove the cache directory) and rebuild.","Update Hugo to pick up WASM/KaTeX protocol fixes.","If persistent, report as a Hugo bug with the LaTeX input."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Clear cache and retry; this is almost always a transient/corrupt-cache issue:\n// 1. hugo --gc   (or rm -rf $TMPDIR/hugo_cache)\n// 2. hugo","preventionTips":["Run `hugo --gc` periodically to keep the cache healthy.","Avoid killing builds mid-write to prevent partial cache files.","Update Hugo for WASM/KaTeX protocol fixes."],"tags":["transform","tomath","cache","json","encoding","internal"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}